diff --git a/Changes b/Changes index 8a7ef4e5f529..268446515cdc 100644 --- a/Changes +++ b/Changes @@ -87,6 +87,9 @@ _______________ command-line of the toplevel. (Nicolás Ojeda Bär, review by Florian Angeletti, report by Daniel Bünzli) +- #12969: Fix a data race in caml_darken_cont + (Fabrice Buoro and Olivier Nicole, review by Gabriel Scherer and Miod Vallat) + OCaml 5.2.0 ------------ diff --git a/runtime/major_gc.c b/runtime/major_gc.c index 78ccf358d310..81134428aadb 100644 --- a/runtime/major_gc.c +++ b/runtime/major_gc.c @@ -1184,8 +1184,12 @@ void caml_darken_cont(value cont) SPIN_WAIT { header_t hd = atomic_load_relaxed(Hp_atomic_val(cont)); CAMLassert(!Has_status_hd(hd, caml_global_heap_state.GARBAGE)); - if (Has_status_hd(hd, caml_global_heap_state.MARKED)) - break; + if (Has_status_hd(hd, caml_global_heap_state.MARKED)) { + /* Perform an acquire load to synchronize with the marking domain */ + hd = atomic_load_acquire(Hp_atomic_val(cont)); + if (Has_status_hd(hd, caml_global_heap_state.MARKED)) + break; + } if (Has_status_hd(hd, caml_global_heap_state.UNMARKED) && atomic_compare_exchange_strong( Hp_atomic_val(cont), &hd,