mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-13 08:35:20 +02:00
Fix synchronization issue at thread start
If a newly spawned thread called getThreadId or getThreadHandle before the spawning thread finished saving the thread handle, then the handle/id would be used uninitialized. This would cause the threading tests to fail since isCurrentThread would return false, and if Minetest is built with C++11 support the std::thread object pointer would be dereferenced while ininitialized, causing a segmentation fault. This fixes the issue by using a mutex to force the spawned thread to wait for the spawning thread to finish initializing the thread object. An alternative way to handle this would be to also set the thread handle/id in the started thread but this wouldn't work for C++11 builds because there's no way to get the partially constructed object.
This commit is contained in:
@@ -153,6 +153,7 @@ private:
|
||||
Atomic<bool> m_request_stop;
|
||||
Atomic<bool> m_running;
|
||||
Mutex m_mutex;
|
||||
Mutex m_start_finished_mutex;
|
||||
|
||||
#if USE_CPP11_THREADS
|
||||
std::thread *m_thread_obj;
|
||||
|
Reference in New Issue
Block a user