summaryrefslogtreecommitdiff
path: root/rts/Task.c
diff options
context:
space:
mode:
authorIavor S. Diatchki <iavor.diatchki@gmail.com>2014-07-19 14:29:57 -0700
committerIavor S. Diatchki <iavor.diatchki@gmail.com>2014-07-19 14:29:57 -0700
commit524634641c61ab42c555452f6f87119b27f6c331 (patch)
treef78d17bb6b09fb3b2e22cb4d93c2a3d45accc2d9 /rts/Task.c
parent79ad1d20c5500e17ce5daaf93b171131669bddad (diff)
parentc41b716d82b1722f909979d02a76e21e9b68886c (diff)
downloadhaskell-wip/ext-solver.tar.gz
Merge branch 'master' into wip/ext-solverwip/ext-solver
Diffstat (limited to 'rts/Task.c')
-rw-r--r--rts/Task.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/rts/Task.c b/rts/Task.c
index 12c22c4b02..842ad84a89 100644
--- a/rts/Task.c
+++ b/rts/Task.c
@@ -39,7 +39,7 @@ static Task * allocTask (void);
static Task * newTask (rtsBool);
#if defined(THREADED_RTS)
-static Mutex all_tasks_mutex;
+Mutex all_tasks_mutex;
#endif
/* -----------------------------------------------------------------------------
@@ -350,6 +350,20 @@ discardTasksExcept (Task *keep)
next = task->all_next;
if (task != keep) {
debugTrace(DEBUG_sched, "discarding task %" FMT_SizeT "", (size_t)TASK_ID(task));
+#if defined(THREADED_RTS)
+ // It is possible that some of these tasks are currently blocked
+ // (in the parent process) either on their condition variable
+ // `cond` or on their mutex `lock`. If they are we may deadlock
+ // when `freeTask` attempts to call `closeCondition` or
+ // `closeMutex` (the behaviour of these functions is documented to
+ // be undefined in the case that there are threads blocked on
+ // them). To avoid this, we re-initialize both the condition
+ // variable and the mutex before calling `freeTask` (we do
+ // precisely the same for all global locks in `forkProcess`).
+ initCondition(&task->cond);
+ initMutex(&task->lock);
+#endif
+
// Note that we do not traceTaskDelete here because
// we are not really deleting a task.
// The OS threads for all these tasks do not exist in