aboutsummaryrefslogtreecommitdiff
path: root/src/zenutil/workerpools.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-12-04 05:16:22 -0500
committerGitHub <[email protected]>2023-12-04 11:16:22 +0100
commitaeecf717fee464ac2b9700e571d19c0c51794d7b (patch)
treec6b3abb9edca18d7b43b59b726b01245b26ba6ba /src/zenutil/workerpools.cpp
parentuse 32 bit offset and size in BlockStoreLocation (#581) (diff)
downloadzen-aeecf717fee464ac2b9700e571d19c0c51794d7b.tar.xz
zen-aeecf717fee464ac2b9700e571d19c0c51794d7b.zip
safe threadpool shutdown (#584)
* shut down thread pools earlier to worker threads has a chance to terminate before main thread atexit
Diffstat (limited to 'src/zenutil/workerpools.cpp')
-rw-r--r--src/zenutil/workerpools.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/zenutil/workerpools.cpp b/src/zenutil/workerpools.cpp
index b511b0c5c..3ae302064 100644
--- a/src/zenutil/workerpools.cpp
+++ b/src/zenutil/workerpools.cpp
@@ -14,6 +14,8 @@ namespace {
const int LargeWorkerThreadPoolTreadCount = gsl::narrow<int>(std::thread::hardware_concurrency());
const int SmallWorkerThreadPoolTreadCount = gsl::narrow<int>(Max((std::thread::hardware_concurrency() / 4u), 1u));
+ static bool IsShutDown = false;
+
RwLock PoolLock;
std::unique_ptr<WorkerThreadPool> LargeWorkerPool;
@@ -32,6 +34,7 @@ GetLargeWorkerPool()
}
}
RwLock::ExclusiveLockScope _(PoolLock);
+ ZEN_ASSERT(!IsShutDown);
if (LargeWorkerPool)
{
return *LargeWorkerPool;
@@ -51,6 +54,7 @@ GetSmallWorkerPool()
}
}
RwLock::ExclusiveLockScope _(PoolLock);
+ ZEN_ASSERT(!IsShutDown);
if (SmallWorkerPool)
{
return *SmallWorkerPool;
@@ -70,6 +74,7 @@ GetSyncWorkerPool()
}
}
RwLock::ExclusiveLockScope _(PoolLock);
+ ZEN_ASSERT(!IsShutDown);
if (SyncWorkerPool)
{
return *SyncWorkerPool;
@@ -82,6 +87,7 @@ void
ShutdownWorkerPools()
{
RwLock::ExclusiveLockScope _(PoolLock);
+ IsShutDown = true;
LargeWorkerPool.reset();
SmallWorkerPool.reset();
SyncWorkerPool.reset();