forkProcess: fix task mutex release order
authorÖmer Sinan Ağacan <omeragacan@gmail.com>
Fri, 2 Mar 2018 16:15:03 +0000 (11:15 -0500)
committerBen Gamari <ben@smart-cactus.org>
Fri, 2 Mar 2018 16:16:47 +0000 (11:16 -0500)
`all_tasks_mutex` should be released before calling `releaseCapability_`
in the parent process as `releaseCapability_` spawns worker tasks in
some cases.

Reviewers: bgamari, erikd, simonmar

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14538

Differential Revision: https://phabricator.haskell.org/D4460

rts/Schedule.c

index f1363e4..cdb9659 100644 (file)
@@ -2004,15 +2004,15 @@ forkProcess(HsStablePtr *entry
         RELEASE_LOCK(&stable_mutex);
         RELEASE_LOCK(&task->lock);
 
+#if defined(THREADED_RTS)
+        RELEASE_LOCK(&all_tasks_mutex);
+#endif
+
         for (i=0; i < n_capabilities; i++) {
             releaseCapability_(capabilities[i],false);
             RELEASE_LOCK(&capabilities[i]->lock);
         }
 
-#if defined(THREADED_RTS)
-        RELEASE_LOCK(&all_tasks_mutex);
-#endif
-
         boundTaskExiting(task);
 
         // just return the pid