diff --git a/sycl/source/detail/scheduler/scheduler.cpp b/sycl/source/detail/scheduler/scheduler.cpp index 1ca92d93080c4..8c67225b7b98b 100644 --- a/sycl/source/detail/scheduler/scheduler.cpp +++ b/sycl/source/detail/scheduler/scheduler.cpp @@ -12,9 +12,11 @@ #include #include +#include #include #include #include +#include #include __SYCL_INLINE_NAMESPACE(cl) { @@ -268,7 +270,11 @@ void Scheduler::lockSharedTimedMutex( // TODO: after switching to C++17, change std::shared_timed_mutex to // std::shared_mutex and use std::lock_guard here both for Windows and Linux. while (!Lock.owns_lock()) { - Lock.try_lock(); + Lock.try_lock_for(std::chrono::milliseconds(10)); + // Without yield while loop acts like endless while loop and occupies the + // whole CPU when multiple command groups are created in multiple host + // threads + std::this_thread::yield(); } #else // It is a deadlock on UNIX in implementation of lock and lock_shared, if