@@ -302,6 +302,11 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
302302 self . threads [ thread_id] . state == ThreadState :: Terminated
303303 }
304304
305+ /// Have all threads terminated?
306+ fn have_all_terminated ( & self ) -> bool {
307+ self . threads . iter ( ) . all ( |thread| thread. state == ThreadState :: Terminated )
308+ }
309+
305310 /// Enable the thread for execution. The thread must be terminated.
306311 fn enable_thread ( & mut self , thread_id : ThreadId ) {
307312 assert ! ( self . has_terminated( thread_id) ) ;
@@ -491,15 +496,7 @@ impl<'mir, 'tcx: 'mir> ThreadManager<'mir, 'tcx> {
491496 // If we get here again and the thread is *still* terminated, there are no more dtors to run.
492497 if self . threads [ MAIN_THREAD ] . state == ThreadState :: Terminated {
493498 // The main thread terminated; stop the program.
494- if self . threads . iter ( ) . any ( |thread| thread. state != ThreadState :: Terminated ) {
495- // FIXME: This check should be either configurable or just emit
496- // a warning. For example, it seems normal for a program to
497- // terminate without waiting for its detached threads to
498- // terminate. However, this case is not trivial to support
499- // because we also probably do not want to consider the memory
500- // owned by these threads as leaked.
501- throw_unsup_format ! ( "the main thread terminated without waiting for other threads" ) ;
502- }
499+ // We do *not* run TLS dtors of remaining threads, which seems to match rustc behavior.
503500 return Ok ( SchedulingAction :: Stop ) ;
504501 }
505502 // This thread and the program can keep going.
@@ -645,6 +642,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
645642 this. machine . threads . has_terminated ( thread_id)
646643 }
647644
645+ #[ inline]
646+ fn have_all_terminated ( & self ) -> bool {
647+ let this = self . eval_context_ref ( ) ;
648+ this. machine . threads . have_all_terminated ( )
649+ }
650+
648651 #[ inline]
649652 fn enable_thread ( & mut self , thread_id : ThreadId ) {
650653 let this = self . eval_context_mut ( ) ;
0 commit comments