Skip to content
Permalink
Browse files

Thread: fix a crash on Windows due to data race condition on Thread::…

…m_start_finished_mutex (#6515)
  • Loading branch information...
nerzhul committed Oct 10, 2017
1 parent 9d29590 commit 32ae4926578844eac1a7b72fcd4e26eb854eb7e5
Showing with 6 additions and 2 deletions.
  1. +6 −2 src/threading/thread.cpp
@@ -74,8 +74,8 @@ Thread::~Thread()
kill();

// Make sure start finished mutex is unlocked before it's destroyed
m_start_finished_mutex.try_lock();
m_start_finished_mutex.unlock();
if (m_start_finished_mutex.try_lock())
m_start_finished_mutex.unlock();

}

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

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

0 comments on commit 32ae492

Please sign in to comment.
You can’t perform that action at this time.