From 1e7b5d6fdb09e08b024fe5461c12efee92032936 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 30 Apr 2022 16:04:19 +0200 Subject: Fix synchronization issue at thread start If a newly started thread immediately exits then m_running would immediately be set to false again and the caller would be stuck waiting for m_running to become true forever. Since a mutex for synchronizing startup already exists we can simply move the while loop into it. see also: #5134 which introduced m_start_finished_mutex --- src/threading/thread.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/threading/thread.cpp') diff --git a/src/threading/thread.cpp b/src/threading/thread.cpp index 5cfc60995..ef025ac1d 100644 --- a/src/threading/thread.cpp +++ b/src/threading/thread.cpp @@ -121,12 +121,12 @@ bool Thread::start() return false; } - // Allow spawned thread to continue - m_start_finished_mutex.unlock(); - while (!m_running) sleep_ms(1); + // Allow spawned thread to continue + m_start_finished_mutex.unlock(); + m_joinable = true; return true; -- cgit v1.2.3