File tree Expand file tree Collapse file tree 1 file changed +5
-0
lines changed Expand file tree Collapse file tree 1 file changed +5
-0
lines changed Original file line number Diff line number Diff line change @@ -638,12 +638,17 @@ void jl_gc_run_all_finalizers(jl_task_t *ct)
638638 jl_ptls_t * gc_all_tls_states ;
639639 gc_n_threads = jl_atomic_load_acquire (& jl_n_threads );
640640 gc_all_tls_states = jl_atomic_load_relaxed (& jl_all_tls_states );
641+ // this is called from `jl_atexit_hook`; threads could still be running
642+ // so we have to guard the finalizers' lists
643+ JL_LOCK_NOGC (& finalizers_lock );
641644 schedule_all_finalizers (& finalizer_list_marked );
642645 for (int i = 0 ; i < gc_n_threads ; i ++ ) {
643646 jl_ptls_t ptls2 = gc_all_tls_states [i ];
644647 if (ptls2 )
645648 schedule_all_finalizers (& ptls2 -> finalizers );
646649 }
650+ // unlock here because `run_finalizers` locks this
651+ JL_UNLOCK_NOGC (& finalizers_lock );
647652 gc_n_threads = 0 ;
648653 gc_all_tls_states = NULL ;
649654 run_finalizers (ct );
You can’t perform that action at this time.
0 commit comments