Detect C finalizer callbacks in rts_lock() instead of schedule()
authorSimon Marlow <marlowsd@gmail.com>
Wed, 19 Aug 2009 12:32:08 +0000 (12:32 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Wed, 19 Aug 2009 12:32:08 +0000 (12:32 +0000)
Otherwise, finalizer callbacks cause a deadlock in the threaded RTS
(including GHCi)

rts/RtsAPI.c
rts/Schedule.c

index 3eecab1..54d1e75 100644 (file)
@@ -16,6 +16,7 @@
 #include "Schedule.h"
 #include "Capability.h"
 #include "Stable.h"
+#include "Weak.h"
 
 /* ----------------------------------------------------------------------------
    Building Haskell objects from C datatypes.
@@ -537,6 +538,14 @@ rts_lock (void)
     Capability *cap;
     Task *task;
 
+    if (running_finalizers) {
+        errorBelch("error: a C finalizer called back into Haskell.\n"
+                   "   This was previously allowed, but is disallowed in GHC 6.10.2 and later.\n"
+                   "   To create finalizers that may call back into Haskll, use\n"
+                   "   Foreign.Concurrent.newForeignPtr instead of Foreign.newForeignPtr.");
+        stg_exit(EXIT_FAILURE);
+    }
+
     task = newBoundTask();
 
     cap = NULL;
index dd33f6f..70601c3 100644 (file)
@@ -252,14 +252,6 @@ schedule (Capability *initialCapability, Task *task)
              "### NEW SCHEDULER LOOP (task: %p, cap: %p)",
              task, initialCapability);
 
-  if (running_finalizers) {
-      errorBelch("error: a C finalizer called back into Haskell.\n"
-                 "   This was previously allowed, but is disallowed in GHC 6.10.2 and later.\n"
-                 "   To create finalizers that may call back into Haskll, use\n"
-                 "   Foreign.Concurrent.newForeignPtr instead of Foreign.newForeignPtr.");
-      stg_exit(EXIT_FAILURE);
-  }
-
   schedulePreLoop();
 
   // -----------------------------------------------------------