X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FTask.c;h=7120436bb47d387ef3484bffe53d2877e2d8df05;hb=63179a7b10069d8f69f5bceef27008c9c7fb0aa8;hp=4a630843b725cec6aa1afaff7e26417dac2a06ae;hpb=1f801e3abd16559f2120b7f482b19deb0c43a0c7;p=ghc-hetmet.git diff --git a/rts/Task.c b/rts/Task.c index 4a63084..7120436 100644 --- a/rts/Task.c +++ b/rts/Task.c @@ -84,15 +84,24 @@ freeTaskManager (void) ACQUIRE_LOCK(&sched_mutex); for (task = all_tasks; task != NULL; task = next) { + next = task->all_link; + if (task->stopped) { + // We only free resources if the Task is not in use. A + // Task may still be in use if we have a Haskell thread in + // a foreign call while we are attempting to shut down the + // RTS (see conc059). #if defined(THREADED_RTS) - closeCondition(&task->cond); - closeMutex(&task->lock); + closeCondition(&task->cond); + closeMutex(&task->lock); #endif - next = task->all_link; - stgFree(task); + stgFree(task); + } } all_tasks = NULL; task_free_list = NULL; +#if defined(THREADED_RTS) + freeThreadLocalKey(¤tTaskKey); +#endif RELEASE_LOCK(&sched_mutex); } @@ -105,7 +114,8 @@ newTask (void) #endif Task *task; - task = stgMallocBytes(sizeof(Task), "newTask"); +#define ROUND_TO_CACHE_LINE(x) ((((x)+63) / 64) * 64) + task = stgMallocBytes(ROUND_TO_CACHE_LINE(sizeof(Task)), "newTask"); task->cap = NULL; task->stopped = rtsFalse; @@ -249,6 +259,7 @@ workerTaskStop (Task *task) ASSERT(myTask() == task); #endif + task->cap = NULL; taskTimeStamp(task); task->stopped = rtsTrue; tasksRunning--;