summaryrefslogtreecommitdiff
path: root/src/threading/thread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/threading/thread.cpp')
-rw-r--r--src/threading/thread.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/threading/thread.cpp b/src/threading/thread.cpp
index fbe4ba1f3..4f4c9474a 100644
--- a/src/threading/thread.cpp
+++ b/src/threading/thread.cpp
@@ -101,6 +101,11 @@ Thread::Thread(const std::string &name) :
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();
+
}
@@ -113,6 +118,9 @@ bool Thread::start()
m_request_stop = false;
+ // The mutex may already be locked if the thread is being restarted
+ m_start_finished_mutex.try_lock();
+
#if USE_CPP11_THREADS
try {
@@ -135,6 +143,9 @@ bool Thread::start()
#endif
+ // Allow spawned thread to continue
+ m_start_finished_mutex.unlock();
+
while (!m_running)
sleep_ms(1);
@@ -249,6 +260,10 @@ DWORD WINAPI Thread::threadProc(LPVOID param)
g_logger.registerThread(thr->m_name);
thr->m_running = true;
+ // Wait for the thread that started this one to finish initializing the
+ // thread handle so that getThreadId/getThreadHandle will work.
+ thr->m_start_finished_mutex.lock();
+
thr->m_retval = thr->run();
thr->m_running = false;