Commit b7ea7671 authored by Simon Marlow's avatar Simon Marlow
Browse files

Move the freeing of Capabilities later in the shutdown sequence

Fixes a bug whereby the Capability has been freed but other
Capabilities are still trying to steal sparks from its pool.
parent 4af25e1a
......@@ -767,7 +767,6 @@ shutdownCapability (Capability *cap, Task *task, rtsBool safe)
}
debugTrace(DEBUG_sched, "capability %d is stopped.", cap->no);
freeCapability(cap);
RELEASE_LOCK(&cap->lock);
break;
}
......@@ -805,14 +804,28 @@ tryGrabCapability (Capability *cap, Task *task)
#endif /* THREADED_RTS */
void
freeCapability (Capability *cap) {
static void
freeCapability (Capability *cap)
{
stgFree(cap->mut_lists);
#if defined(THREADED_RTS) || defined(PARALLEL_HASKELL)
freeSparkPool(cap->sparks);
#endif
}
void
freeCapabilities (void)
{
#if defined(THREADED_RTS)
nat i;
for (i=0; i < n_capabilities; i++) {
freeCapability(&capabilities[i]);
}
#else
freeCapability(&MainCapability);
#endif
}
/* ---------------------------------------------------------------------------
Mark everything directly reachable from the Capabilities. When
using multiple GC threads, each GC thread marks all Capabilities
......
......@@ -262,8 +262,8 @@ extern void grabCapability (Capability **pCap);
// cause all capabilities to context switch as soon as possible.
void setContextSwitches(void);
// Free a capability on exit
void freeCapability (Capability *cap);
// Free all capabilities
void freeCapabilities (void);
// FOr the GC:
void markSomeCapabilities (evac_fn evac, void *user, nat i0, nat delta,
......
......@@ -2114,14 +2114,13 @@ exitScheduler(
boundTaskExiting(task);
stopTaskManager();
}
#else
freeCapability(&MainCapability);
#endif
}
void
freeScheduler( void )
{
freeCapabilities();
freeTaskManager();
if (n_capabilities != 1) {
stgFree(capabilities);
......
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