Commit 39630ab1 authored by Edsko de Vries's avatar Edsko de Vries Committed by Austin Seipp

Avoid deadlock in freeTask (called by forkProcess)

Summary: Documented in more detail inline with the change.

Test Plan: validate

Reviewers: austin, simonmar, duncan

Reviewed By: austin, simonmar, duncan

Subscribers: simonmar, relrod, carter

Differential Revision:
parent 1d71e969
......@@ -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`).
// 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment