]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Fix synchronization issue at thread start
authorsfan5 <sfan5@live.de>
Sat, 30 Apr 2022 14:04:19 +0000 (16:04 +0200)
committersfan5 <sfan5@live.de>
Mon, 2 May 2022 18:54:55 +0000 (20:54 +0200)
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

index 5cfc609957eb5ed999afddb932c634a4f3f39be4..ef025ac1d0ea72e29808f5df61b4672149c35aab 100644 (file)
@@ -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;