Browse Source

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
sfan5 2 years ago
parent
commit
663c936428
1 changed files with 3 additions and 3 deletions
  1. 3 3
      src/threading/thread.cpp

+ 3 - 3
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;