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 @@ -526,12 +526,17 @@ void jl_gc_run_all_finalizers(jl_task_t *ct)
526526    jl_ptls_t *  gc_all_tls_states ;
527527    gc_n_threads  =  jl_atomic_load_acquire (& jl_n_threads );
528528    gc_all_tls_states  =  jl_atomic_load_relaxed (& jl_all_tls_states );
529+     // this is called from `jl_atexit_hook`; threads could still be running 
530+     // so we have to guard the finalizers' lists 
531+     JL_LOCK_NOGC (& finalizers_lock );
529532    schedule_all_finalizers (& finalizer_list_marked );
530533    for  (int  i  =  0 ; i  <  gc_n_threads ; i ++ ) {
531534        jl_ptls_t  ptls2  =  gc_all_tls_states [i ];
532535        if  (ptls2  !=  NULL )
533536            schedule_all_finalizers (& ptls2 -> finalizers );
534537    }
538+     // unlock here because `run_finalizers` locks this 
539+     JL_UNLOCK_NOGC (& finalizers_lock );
535540    gc_n_threads  =  0 ;
536541    gc_all_tls_states  =  NULL ;
537542    run_finalizers (ct );
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments