From 2be4ccea37d0c96d35aedaee0b7a80ffe4058715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 2 May 2014 14:04:39 +0200 Subject: [PATCH] Delay deletion of the main thread's event driver to "~shared static this()". --- source/vibe/core/core.d | 11 +++++++++-- source/vibe/core/driver.d | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/source/vibe/core/core.d b/source/vibe/core/core.d index 1334cafc9f..669153a348 100644 --- a/source/vibe/core/core.d +++ b/source/vibe/core/core.d @@ -1149,6 +1149,8 @@ shared static this() shared static ~this() { + deleteEventDriver(); + bool tasks_left = false; synchronized (st_threadsMutex) { @@ -1179,6 +1181,9 @@ static this() static ~this() { auto thisthr = Thread.getThis(); + + bool is_main_thread = false; + synchronized (st_threadsMutex) { auto idx = st_threads.countUntil!(c => c.thread is thisthr); assert(idx >= 0); @@ -1188,7 +1193,8 @@ static ~this() } // if we are the main thread, wait for all others before terminating - if (idx == 0) { // we are the main thread, wait for others + is_main_thread = idx == 0; + if (is_main_thread) { // we are the main thread, wait for others atomicStore(st_term, true); st_threadsSignal.emit(); while (st_threads.length) @@ -1196,7 +1202,8 @@ static ~this() } } - deleteEventDriver(); + // delay deletion of the main event driver to "~shared static this()" + if (!is_main_thread) deleteEventDriver(); st_threadShutdownCondition.notifyAll(); } diff --git a/source/vibe/core/driver.d b/source/vibe/core/driver.d index 739446f8a0..3abd5a8a66 100644 --- a/source/vibe/core/driver.d +++ b/source/vibe/core/driver.d @@ -38,6 +38,7 @@ package void deleteEventDriver() { // TODO: use destroy() instead delete s_driver; + s_driver = null; }