diff --git a/source/adapters/native_cpu/threadpool.hpp b/source/adapters/native_cpu/threadpool.hpp index 55c32eb84b..2f2f79cd5a 100644 --- a/source/adapters/native_cpu/threadpool.hpp +++ b/source/adapters/native_cpu/threadpool.hpp @@ -81,8 +81,11 @@ class worker_thread { // Waits for all tasks to finish and destroys the worker thread inline void stop() { - m_isRunning.store(false, std::memory_order_release); - m_startWorkCondition.notify_all(); + { + std::lock_guard lock(m_workMutex); + m_isRunning.store(false, std::memory_order_release); + m_startWorkCondition.notify_all(); + } if (m_worker.joinable()) { // Wait for the worker thread to finish handling the task queue m_worker.join();