Skip to content

Commit f99b3b5

Browse files
authored
let's prevent GC during thread teardown (#225)
1 parent 0e7de74 commit f99b3b5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/signals-unix.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ static int thread0_exit_signo = 0;
472472
static void JL_NORETURN jl_exit_thread0_cb(void)
473473
{
474474
CFI_NORETURN
475+
jl_atomic_fetch_add(&jl_gc_disable_counter, -1);
475476
jl_critical_error(thread0_exit_signo, 0, NULL, jl_current_task);
476477
jl_atexit_hook(128);
477478
jl_raise(thread0_exit_signo);
@@ -963,6 +964,12 @@ static void *signal_listener(void *arg)
963964
//#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309L && !HAVE_KEVENT
964965
// si_code = info.si_code;
965966
//#endif
967+
// Let's forbid threads from running GC while we're trying to exit,
968+
// also let's make sure we're not in the middle of GC.
969+
jl_atomic_fetch_add(&jl_gc_disable_counter, 1);
970+
while (jl_atomic_load_acquire(&jl_gc_running)) {
971+
jl_cpu_pause();
972+
}
966973
jl_exit_thread0(sig, bt_data, bt_size);
967974
}
968975
else if (critical) {

0 commit comments

Comments
 (0)