Skip to content

Commit

Permalink
Merge pull request #12707 from jmid/domain-assert-failure
Browse files Browse the repository at this point in the history
Fix assertion race condition in #11800
  • Loading branch information
gasche committed Oct 31, 2023
2 parents d73896d + 2ed291f commit 8cc728b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Changes
Expand Up @@ -436,6 +436,9 @@ Working version

### Bug fixes:

- #11800, #12707: fix an assertion race condition in `install_backup_thread`
(Jan Midtgaard, review by Gabriel Scherer)

- #12590, #12595: fix a race in `caml_collect_gc_stats_sample`
(B. Szilvasy, review by Gabriel Scherer)

Expand Down
9 changes: 6 additions & 3 deletions runtime/domain.c
Expand Up @@ -1042,14 +1042,17 @@ static void install_backup_thread (dom_internal* di)
#endif

if (di->backup_thread_running == 0) {
CAMLassert (di->backup_thread_msg == BT_INIT || /* Using fresh domain */
di->backup_thread_msg == BT_TERMINATE); /* Reusing domain */
uintnat msg;
msg = atomic_load_acquire(&di->backup_thread_msg);
CAMLassert (msg == BT_INIT || /* Using fresh domain */
msg == BT_TERMINATE); /* Reusing domain */

while (atomic_load_acquire(&di->backup_thread_msg) != BT_INIT) {
while (msg != BT_INIT) {
/* Give a chance for backup thread on this domain to terminate */
caml_plat_unlock (&di->domain_lock);
cpu_relax ();
caml_plat_lock (&di->domain_lock);
msg = atomic_load_acquire(&di->backup_thread_msg);
}

#ifndef _WIN32
Expand Down

0 comments on commit 8cc728b

Please sign in to comment.