Skip to content

Commit

Permalink
Merge pull request ocaml#12969 from fabbing/race_gc_tracing_free_stack
Browse files Browse the repository at this point in the history
Fix a data race in `caml_darken_cont`
  • Loading branch information
gasche committed Feb 12, 2024
2 parents ec52575 + 7435700 commit ef62c57
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------

Expand Down
8 changes: 6 additions & 2 deletions runtime/major_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ef62c57

Please sign in to comment.