diff options
Diffstat (limited to 'src/threading/thread.cpp')
-rw-r--r-- | src/threading/thread.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/threading/thread.cpp b/src/threading/thread.cpp index fbe4ba1f3..1909da61d 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); @@ -241,7 +252,7 @@ DWORD WINAPI Thread::threadProc(LPVOID param) Thread *thr = (Thread *)param; #ifdef _AIX - m_kernel_thread_id = thread_self(); + thr->m_kernel_thread_id = thread_self(); #endif thr->setName(thr->m_name); @@ -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; |