diff options
author | Simon Marlow <marlowsd@gmail.com> | 2008-11-19 12:48:48 +0000 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2008-11-19 12:48:48 +0000 |
commit | 5cbe7adb6051a9d1738dfb5735c8c923b74c5945 (patch) | |
tree | e79827a16b6d43caf6057fd87be955d67d9ff764 /rts/Task.c | |
parent | 33189c6969f4838dab3558497dd66f7400ee77d0 (diff) | |
download | haskell-5cbe7adb6051a9d1738dfb5735c8c923b74c5945.tar.gz |
Fix some more shutdown races
There were races between workerTaskStop() and freeTaskManager(): we
need to be sure that all Tasks have exited properly before we start
tearing things down. This isn't completely straighforward, see
comments for details.
Diffstat (limited to 'rts/Task.c')
-rw-r--r-- | rts/Task.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/rts/Task.c b/rts/Task.c index 7120436bb4..9397789105 100644 --- a/rts/Task.c +++ b/rts/Task.c @@ -64,25 +64,16 @@ initTaskManager (void) } } - -void -stopTaskManager (void) -{ - debugTrace(DEBUG_sched, - "stopping task manager, %d tasks still running", - tasksRunning); - /* nothing to do */ -} - - -void +nat freeTaskManager (void) { Task *task, *next; - debugTrace(DEBUG_sched, "freeing task manager"); + ASSERT_LOCK_HELD(&sched_mutex); + + debugTrace(DEBUG_sched, "freeing task manager, %d tasks still running", + tasksRunning); - ACQUIRE_LOCK(&sched_mutex); for (task = all_tasks; task != NULL; task = next) { next = task->all_link; if (task->stopped) { @@ -102,7 +93,8 @@ freeTaskManager (void) #if defined(THREADED_RTS) freeThreadLocalKey(¤tTaskKey); #endif - RELEASE_LOCK(&sched_mutex); + + return tasksRunning; } @@ -149,7 +141,6 @@ newTask (void) all_tasks = task; taskCount++; - workerCount++; return task; } @@ -185,6 +176,7 @@ newBoundTask (void) void boundTaskExiting (Task *task) { + task->tso = NULL; task->stopped = rtsTrue; task->cap = NULL; @@ -218,7 +210,11 @@ discardTask (Task *task) if (!task->stopped) { debugTrace(DEBUG_sched, "discarding task %ld", (long)TASK_ID(task)); task->cap = NULL; - task->tso = NULL; + if (task->tso == NULL) { + workerCount--; + } else { + task->tso = NULL; + } task->stopped = rtsTrue; tasksRunning--; task->next = task_free_list; @@ -263,6 +259,7 @@ workerTaskStop (Task *task) taskTimeStamp(task); task->stopped = rtsTrue; tasksRunning--; + workerCount--; ACQUIRE_LOCK(&sched_mutex); task->next = task_free_list; |