diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-10-10 12:27:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-10 12:27:08 +0200 |
commit | 32ae4926578844eac1a7b72fcd4e26eb854eb7e5 (patch) | |
tree | 190211664f52e3cb25c6d5c6703cb371b34a9c86 /src/threading | |
parent | 9d295906efc7eec58dba3f7494f4e444d2c8d00f (diff) | |
download | minetest-32ae4926578844eac1a7b72fcd4e26eb854eb7e5.tar.gz minetest-32ae4926578844eac1a7b72fcd4e26eb854eb7e5.tar.bz2 minetest-32ae4926578844eac1a7b72fcd4e26eb854eb7e5.zip |
Thread: fix a crash on Windows due to data race condition on Thread::m_start_finished_mutex (#6515)
Diffstat (limited to 'src/threading')
-rw-r--r-- | src/threading/thread.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/threading/thread.cpp b/src/threading/thread.cpp index 09cc7d836..3b6851389 100644 --- a/src/threading/thread.cpp +++ b/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(); } |