summaryrefslogtreecommitdiff
path: root/rts/Task.c
diff options
context:
space:
mode:
authorGabor Greif <ggreif@gmail.com>2014-08-08 18:01:19 +0200
committerGabor Greif <ggreif@gmail.com>2014-08-08 18:01:19 +0200
commit5f003d228340c3ce8e500f9053f353c58dc1dc94 (patch)
treea855b0f173ff635b48354e1136ef6cbb2a1214a4 /rts/Task.c
parentff9c5570395bcacf8963149b3a8475f5644ce694 (diff)
parentdff0623d5ab13222c06b3ff6b32793e05b417970 (diff)
downloadhaskell-wip/generics-propeq.tar.gz
Merge branch 'master' into wip/generics-propeqwip/generics-propeq
Conflicts: compiler/typecheck/TcGenGenerics.lhs
Diffstat (limited to 'rts/Task.c')
-rw-r--r--rts/Task.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/rts/Task.c b/rts/Task.c
index 12c22c4b02..0421d8b785 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
@@ -502,3 +516,11 @@ printAllTasks(void)
#endif
+
+// Local Variables:
+// mode: C
+// fill-column: 80
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End: