Skip to content

Commit b1bb419

Browse files
Merge pull request #1965 from PietroGhg/pietro/lock_stop_thread
[NATIVECPU] Add lock_guard when stopping threads
2 parents d155388 + 10dfe6b commit b1bb419

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

source/adapters/native_cpu/threadpool.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ class worker_thread {
8181

8282
// Waits for all tasks to finish and destroys the worker thread
8383
inline void stop() {
84-
m_isRunning.store(false, std::memory_order_release);
85-
m_startWorkCondition.notify_all();
84+
{
85+
std::lock_guard<std::mutex> lock(m_workMutex);
86+
m_isRunning.store(false, std::memory_order_release);
87+
m_startWorkCondition.notify_all();
88+
}
8689
if (m_worker.joinable()) {
8790
// Wait for the worker thread to finish handling the task queue
8891
m_worker.join();

0 commit comments

Comments
 (0)