Fix thread pool shutdown race

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Antonio S. Musumeci
2026-04-10 14:18:02 -04:00
co-authored by Copilot
parent 462020d19a
commit d1bcde3753
+4 -3
View File
@@ -686,12 +686,13 @@ inline
void
ThreadPool::_remove_self(pthread_t t_)
{
// During shutdown the destructor owns all joins; don't detach.
mutex_lockguard(_threads_mutex);
// Check _stop under the lock so the destructor can't snapshot this
// thread for joining and then race with us detaching ourselves.
if(_stop.load(std::memory_order_acquire))
return;
mutex_lockguard(_threads_mutex);
auto it = std::find(_threads.begin(),_threads.end(),t_);
if(it != _threads.end())
{