Skip to content

Commit 27fc101

Browse files
committed
Apply lock before schedule finalizers
1 parent fdada6c commit 27fc101

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/gc-common.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,18 @@ void jl_gc_run_all_finalizers(jl_task_t *ct)
339339
jl_ptls_t* gc_all_tls_states;
340340
gc_n_threads = jl_atomic_load_acquire(&jl_n_threads);
341341
gc_all_tls_states = jl_atomic_load_relaxed(&jl_all_tls_states);
342+
// this is called from `jl_atexit_hook`; threads could still be running
343+
// so we have to guard the finalizers' lists
344+
JL_LOCK_NOGC(&finalizers_lock);
342345
schedule_all_finalizers(&finalizer_list_marked);
343346
for (int i = 0; i < gc_n_threads; i++) {
344347
jl_ptls_t ptls2 = gc_all_tls_states[i];
345348
if (ptls2 != NULL)
346349
schedule_all_finalizers(&ptls2->finalizers);
347350
}
351+
// this is called from `jl_atexit_hook`; threads could still be running
352+
// so we have to guard the finalizers' lists
353+
JL_LOCK_NOGC(&finalizers_lock);
348354
gc_n_threads = 0;
349355
gc_all_tls_states = NULL;
350356
run_finalizers(ct);

0 commit comments

Comments
 (0)