Another shutdown fix
authorSimon Marlow <marlowsd@gmail.com>
Mon, 17 Nov 2008 09:43:50 +0000 (09:43 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Mon, 17 Nov 2008 09:43:50 +0000 (09:43 +0000)
If we encounter a runnable thread during shutdown, just kill it.  All
the threads are supposed to be dead at this stage, but this catches
threads that might have just returned from a foreign call, or were
finalizers created by the GC.

Fixes memo002(threaded1)

rts/Schedule.c

index aedd6b7..d25a321 100644 (file)
@@ -460,6 +460,15 @@ schedule (Capability *initialCapability, Task *task)
     }
 #endif
 
+    // If we're shutting down, and this thread has not yet been
+    // killed, kill it now.  This sometimes happens when a finalizer
+    // thread is created by the final GC, or a thread previously
+    // in a foreign call returns.
+    if (sched_state >= SCHED_INTERRUPTING &&
+        !(t->what_next == ThreadComplete || t->what_next == ThreadKilled)) {
+        deleteThread_(cap,t);
+    }
+
     /* context switches are initiated by the timer signal, unless
      * the user specified "context switch as often as possible", with
      * +RTS -C0