diff --git a/sycl/source/detail/device_impl.hpp b/sycl/source/detail/device_impl.hpp index 280a6d053c788..8c989f0f3d488 100644 --- a/sycl/source/detail/device_impl.hpp +++ b/sycl/source/detail/device_impl.hpp @@ -2318,10 +2318,20 @@ class device_impl { void unregisterQueue(queue_impl *Q) { std::lock_guard Lock(MQueuesMutex); auto It = std::find(MQueues.begin(), MQueues.end(), Q); - assert(It != MQueues.end() && "Queue not found in device's queue list"); - // Swap with last element and pop — O(1) removal, order doesn't matter. - std::swap(*It, MQueues.back()); - MQueues.pop_back(); + + // device_impl can be destroyed before queue_impl in unittests. + // On Windows, unittests involving host tasks race with scheduler + // cleanup (invoked by ~UrMock). UrMock constructor destroys the + // platform cache, along with device_impl. Now, when two unittests + // involving host tasks run one after another, URMock destructor of + // first can race with URMock constructor of second, causing device_impl + // to not have registered queue. + if (It != MQueues.end()) { + // Swap with last element and pop — O(1) removal, + // order doesn't matter. + std::swap(*It, MQueues.back()); + MQueues.pop_back(); + } } private: diff --git a/sycl/unittests/scheduler/InOrderQueueHostTaskDeps.cpp b/sycl/unittests/scheduler/InOrderQueueHostTaskDeps.cpp index a46e8a9691867..8e365878098ad 100644 --- a/sycl/unittests/scheduler/InOrderQueueHostTaskDeps.cpp +++ b/sycl/unittests/scheduler/InOrderQueueHostTaskDeps.cpp @@ -127,12 +127,7 @@ TEST_F(SchedulerTest, InOrderQueueCrossDeps) { EXPECT_EQ(std::get<1>(ExecutedCommands[2]) /*EventsCount*/, 0u); } -#ifdef _WIN32 -// https://github.com/intel/llvm/issues/22412 -TEST_F(SchedulerTest, DISABLED_InOrderQueueCrossDepsShortcutFuncs) { -#else TEST_F(SchedulerTest, InOrderQueueCrossDepsShortcutFuncs) { -#endif ExecutedCommands.clear(); sycl::unittest::UrMock<> Mock; mock::getCallbacks().set_before_callback(