Skip to content

Commit 32ae492

Browse files
authoredOct 10, 2017
Thread: fix a crash on Windows due to data race condition on Thread::m_start_finished_mutex (#6515)
1 parent 9d29590 commit 32ae492

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed
 

‎src/threading/thread.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ Thread::~Thread()
7474
kill();
7575

7676
// Make sure start finished mutex is unlocked before it's destroyed
77-
m_start_finished_mutex.try_lock();
78-
m_start_finished_mutex.unlock();
77+
if (m_start_finished_mutex.try_lock())
78+
m_start_finished_mutex.unlock();
7979

8080
}
8181

@@ -196,6 +196,10 @@ void Thread::threadProc(Thread *thr)
196196
thr->m_retval = thr->run();
197197

198198
thr->m_running = false;
199+
// Unlock m_start_finished_mutex to prevent data race condition on Windows.
200+
// On Windows with VS2017 build TerminateThread is called and this mutex is not
201+
// released. We try to unlock it from caller thread and it's refused by system.
202+
thr->m_start_finished_mutex.unlock();
199203
g_logger.deregisterThread();
200204
}
201205

0 commit comments

Comments
 (0)
Please sign in to comment.