Fix data race in ParallelDispatchThreadPool destruction

This commit is contained in:
Robert O'Callahan
2026-04-07 23:21:17 +00:00
parent a96cf8cc2b
commit d586af0074
+4 -1
View File
@@ -232,7 +232,6 @@ private:
} }
void run_worker(int thread_num); void run_worker(int thread_num);
std::unique_ptr<ThreadPool> thread_pool;
std::function<void(const RunCtx &)> *current_work = nullptr; std::function<void(const RunCtx &)> *current_work = nullptr;
// Keeps a correct count even when threads are exiting. // Keeps a correct count even when threads are exiting.
int num_worker_threads_; int num_worker_threads_;
@@ -291,6 +290,10 @@ private:
done_workers.store(0, std::memory_order_relaxed); done_workers.store(0, std::memory_order_relaxed);
} }
#endif #endif
// Ensure `thread_pool` is destroyed before any other members,
// forcing all threads to be joined before destroying the
// members (e.g. workers_to_main_signal_mutex) they might be using.
std::unique_ptr<ThreadPool> thread_pool;
}; };
template <class T> template <class T>