diff --git a/sycl/unittests/thread_safety/DeviceGlobalProgramHandle.cpp b/sycl/unittests/thread_safety/DeviceGlobalProgramHandle.cpp index 0151d8b74cf73..dbea95be83342 100644 --- a/sycl/unittests/thread_safety/DeviceGlobalProgramHandle.cpp +++ b/sycl/unittests/thread_safety/DeviceGlobalProgramHandle.cpp @@ -81,9 +81,6 @@ struct KernelInfo static sycl::unittest::MockDeviceImage generateHandleTestImage() { using namespace sycl::unittest; - sycl::detail::device_global_map::add(&g_TestDevGlobal, - DevGlobHandleTestGlobalName); - MockPropertySet PropSet; MockProperty DevGlobInfo = makeDeviceGlobalInfo(DevGlobHandleTestGlobalName, sizeof(DevGlobElem), @@ -159,6 +156,11 @@ static ur_result_t blocking_urProgramBuildExp(void *) { class DeviceGlobalProgramHandleTest : public ::testing::Test { protected: void SetUp() override { + // Register the device_global here rather than during static initialization + // to avoid static initialization order fiasco with GlobalHandler + sycl::detail::device_global_map::add(&g_TestDevGlobal, + DevGlobHandleTestGlobalName); + { std::lock_guard HLock(g_HandlesMtx); g_CapturedHandles.clear();