Fix data race lazy-init spin lock deadlock on Windows.
PiperOrigin-RevId: 942556300 Change-Id: Iffe7a3e71c0f6273603e2ada14bf8d924b0ee6cf
This commit is contained in:
committed by
Copybara-Service
parent
11f1da0c44
commit
4a9364082e
@@ -21,6 +21,12 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <windows.h>
|
||||||
|
#elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__EMSCRIPTEN__)
|
||||||
|
#include <sched.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
|
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -152,7 +158,11 @@ static const mjLogConfig* mju_getLogConfigPtr(void) {
|
|||||||
} else {
|
} else {
|
||||||
// another thread is initializing; spin until it completes
|
// another thread is initializing; spin until it completes
|
||||||
while (!mj_atomic_load_bool(&env_init_done)) {
|
while (!mj_atomic_load_bool(&env_init_done)) {
|
||||||
// empty
|
#if defined(_WIN32)
|
||||||
|
Sleep(0);
|
||||||
|
#elif defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__EMSCRIPTEN__)
|
||||||
|
sched_yield();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user