aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/zenserver/zenserver.cpp3
-rw-r--r--src/zenutil/workerpools.cpp6
2 files changed, 8 insertions, 1 deletions
diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp
index 2430267c1..f663417fb 100644
--- a/src/zenserver/zenserver.cpp
+++ b/src/zenserver/zenserver.cpp
@@ -643,6 +643,8 @@ ZenServer::Cleanup()
Flush();
+ ShutdownWorkerPools();
+
m_AdminService.reset();
m_VfsService.reset();
m_ObjStoreService.reset();
@@ -660,7 +662,6 @@ ZenServer::Cleanup()
m_AuthMgr.reset();
m_Http = {};
m_JobQueue.reset();
- ShutdownWorkerPools();
}
catch (std::exception& Ex)
{
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();