Skip to content

Commit

Permalink
Lock finalizers lists at exit (#49931)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpamnany committed May 23, 2023
1 parent 1380bf5 commit 715cff2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,18 @@ static void schedule_all_finalizers(arraylist_t *flist) JL_NOTSAFEPOINT

void jl_gc_run_all_finalizers(jl_task_t *ct)
{
// this is called from `jl_atexit_hook`; threads could still be running
// so we have to guard the finalizers' lists
JL_LOCK_NOGC(&finalizers_lock);
schedule_all_finalizers(&finalizer_list_marked);
// This could be run before we had a chance to setup all threads
for (int i = 0;i < jl_n_threads;i++) {
jl_ptls_t ptls2 = jl_all_tls_states[i];
if (ptls2)
schedule_all_finalizers(&ptls2->finalizers);
}
// unlock here because `run_finalizers` locks this
JL_UNLOCK_NOGC(&finalizers_lock);
run_finalizers(ct);
}

Expand Down

0 comments on commit 715cff2

Please sign in to comment.