- IF_DEBUG(scheduler, sched_belch("stopping task manager, %d tasks still running", tasksRunning));
+ Task *task, *next;
+
+ debugTrace(DEBUG_sched,
+ "stopping task manager, %d tasks still running",
+ tasksRunning);
+
+ ACQUIRE_LOCK(&sched_mutex);
+ for (task = task_free_list; task != NULL; task = next) {
+ next = task->next;
+#if defined(THREADED_RTS)
+ closeCondition(&task->cond);
+ closeMutex(&task->lock);
+#endif
+ stgFree(task);
+ }
+ task_free_list = NULL;
+ RELEASE_LOCK(&sched_mutex);