From c93f7f5ceaf255bc9314be022b7bebb55b1d0605 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Sat, 28 Jan 2017 17:02:43 -0500 Subject: 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. --- src/unittest/test_threading.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/unittest') diff --git a/src/unittest/test_threading.cpp b/src/unittest/test_threading.cpp index cdbf9674e..e1e1d3660 100644 --- a/src/unittest/test_threading.cpp +++ b/src/unittest/test_threading.cpp @@ -39,9 +39,7 @@ static TestThreading g_test_instance; void TestThreading::runTests(IGameDef *gamedef) { -#if !(defined(__MACH__) && defined(__APPLE__)) TEST(testStartStopWait); -#endif TEST(testThreadKill); TEST(testAtomicSemaphoreThread); } -- cgit v1.2.3