summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-10-10 12:27:08 +0200
committerSmallJoker <mk939@ymail.com>2018-06-03 17:31:59 +0200
commit0129c9a9dd149f4e5efaed1879c1c3058cbc4d70 (patch)
tree70985e417af22c652c5e7742bbd426b97ec1e967
parent9dc1f2d638ddde253fbfac26c856b5da4ea1495f (diff)
downloadminetest-0129c9a9dd149f4e5efaed1879c1c3058cbc4d70.tar.gz
minetest-0129c9a9dd149f4e5efaed1879c1c3058cbc4d70.tar.bz2
minetest-0129c9a9dd149f4e5efaed1879c1c3058cbc4d70.zip
Thread: fix a crash on Windows due to data race condition on Thread::m_start_finished_mutex (#6515)
-rw-r--r--src/threading/thread.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/threading/thread.cpp b/src/threading/thread.cpp
index 1909da61d..e3dde24cd 100644
--- a/src/threading/thread.cpp
+++ b/src/threading/thread.cpp
@@ -103,8 +103,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();
}
@@ -267,6 +267,10 @@ DWORD WINAPI Thread::threadProc(LPVOID param)
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 is returned here to avoid an unnecessary ifdef clause