Fix shutdown of the worker thread pool.
Shuts down the pool before terminating the threads to avoid accessing an event thread waiter slot that is not associated with a valid eventcore driver anymore.
This commit is contained in:
parent
53ea380df8
commit
d2146e3881
|
@ -254,6 +254,7 @@ void exitEventLoop(bool shutdown_all_threads = false)
|
||||||
assert(s_eventLoopRunning || shutdown_all_threads, "Exiting event loop when none is running.");
|
assert(s_eventLoopRunning || shutdown_all_threads, "Exiting event loop when none is running.");
|
||||||
if (shutdown_all_threads) {
|
if (shutdown_all_threads) {
|
||||||
() @trusted nothrow {
|
() @trusted nothrow {
|
||||||
|
shutdownWorkerPool();
|
||||||
atomicStore(st_term, true);
|
atomicStore(st_term, true);
|
||||||
st_threadsSignal.emit();
|
st_threadsSignal.emit();
|
||||||
} ();
|
} ();
|
||||||
|
@ -1349,13 +1350,8 @@ static ~this()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_main_thread) {
|
if (is_main_thread) {
|
||||||
shared(TaskPool) tpool;
|
|
||||||
synchronized (st_threadsMutex) swap(tpool, st_workerPool);
|
|
||||||
if (tpool) {
|
|
||||||
logDiagnostic("Main thread still waiting for worker threads.");
|
|
||||||
tpool.terminate();
|
|
||||||
}
|
|
||||||
logDiagnostic("Main thread exiting");
|
logDiagnostic("Main thread exiting");
|
||||||
|
shutdownWorkerPool();
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (st_threadsMutex) {
|
synchronized (st_threadsMutex) {
|
||||||
|
@ -1373,6 +1369,19 @@ static ~this()
|
||||||
st_threadShutdownCondition.notifyAll();
|
st_threadShutdownCondition.notifyAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void shutdownWorkerPool()
|
||||||
|
nothrow {
|
||||||
|
shared(TaskPool) tpool;
|
||||||
|
|
||||||
|
try synchronized (st_threadsMutex) swap(tpool, st_workerPool);
|
||||||
|
catch (Exception e) assert(false, e.msg);
|
||||||
|
|
||||||
|
if (tpool) {
|
||||||
|
logDiagnostic("Still waiting for worker threads to exit.");
|
||||||
|
tpool.terminate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void shutdownDriver()
|
private void shutdownDriver()
|
||||||
{
|
{
|
||||||
if (ManualEvent.ms_threadEvent != EventID.init) {
|
if (ManualEvent.ms_threadEvent != EventID.init) {
|
||||||
|
|
Loading…
Reference in a new issue