X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FTask.c;h=7120436bb47d387ef3484bffe53d2877e2d8df05;hb=63179a7b10069d8f69f5bceef27008c9c7fb0aa8;hp=551f13777a645eea4f9d8023333a88db4e682754;hpb=6ffb1cec5bc6fcc834547fc456322d2eb2418ff6;p=ghc-hetmet.git diff --git a/rts/Task.c b/rts/Task.c index 551f137..7120436 100644 --- a/rts/Task.c +++ b/rts/Task.c @@ -83,15 +83,25 @@ freeTaskManager (void) debugTrace(DEBUG_sched, "freeing task manager"); ACQUIRE_LOCK(&sched_mutex); - for (task = task_free_list; task != NULL; task = next) { + 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->next; - stgFree(task); + stgFree(task); + } } + all_tasks = NULL; task_free_list = NULL; +#if defined(THREADED_RTS) + freeThreadLocalKey(¤tTaskKey); +#endif RELEASE_LOCK(&sched_mutex); } @@ -104,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; @@ -248,9 +259,15 @@ workerTaskStop (Task *task) ASSERT(myTask() == task); #endif + task->cap = NULL; taskTimeStamp(task); task->stopped = rtsTrue; tasksRunning--; + + ACQUIRE_LOCK(&sched_mutex); + task->next = task_free_list; + task_free_list = task; + RELEASE_LOCK(&sched_mutex); } void