Skip to content

Commit 588615e

Browse files
authored
Merge pull request #1371 from pbalcer/l0-query-status-sync-deadlock
[L0] fix a deadlock in queue sync and event status query
2 parents 4e69cc6 + 4708475 commit 588615e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

source/adapters/level_zero/event.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetInfo(
399399
auto UrQueue = Event->UrQueue;
400400
if (UrQueue) {
401401
// Lock automatically releases when this goes out of scope.
402-
std::scoped_lock<ur_shared_mutex> lock(UrQueue->Mutex);
403-
const auto &OpenCommandList = UrQueue->eventOpenCommandList(Event);
404-
if (OpenCommandList != UrQueue->CommandListMap.end()) {
405-
UR_CALL(UrQueue->executeOpenCommandList(
406-
OpenCommandList->second.isCopy(UrQueue)));
402+
std::unique_lock<ur_shared_mutex> Lock(UrQueue->Mutex, std::try_to_lock);
403+
// If we fail to acquire the lock, it's possible that the queue might
404+
// already be waiting for this event in synchronize().
405+
if (Lock.owns_lock()) {
406+
const auto &OpenCommandList = UrQueue->eventOpenCommandList(Event);
407+
if (OpenCommandList != UrQueue->CommandListMap.end()) {
408+
UR_CALL(UrQueue->executeOpenCommandList(
409+
OpenCommandList->second.isCopy(UrQueue)));
410+
}
407411
}
408412
}
409413

0 commit comments

Comments
 (0)