diff --git a/unified-runtime/source/adapters/level_zero/queue.cpp b/unified-runtime/source/adapters/level_zero/queue.cpp index 35bf1a63d84e..8a0bd1127965 100644 --- a/unified-runtime/source/adapters/level_zero/queue.cpp +++ b/unified-runtime/source/adapters/level_zero/queue.cpp @@ -630,11 +630,12 @@ ur_result_t urQueueRelease( UR_CALL(Queue->synchronize()); // Cleanup the allocations from 'AsyncPool' made by this queue. - Queue->Context->AsyncPool.cleanupPoolsForQueue(Queue); + std::shared_lock ContextLock(Queue->Context->Mutex); for (auto &Pool : Queue->Context->UsmPoolHandles) { Pool->cleanupPoolsForQueue(Queue); } + ContextLock.unlock(); // Destroy all the fences created associated with this queue. for (auto it = Queue->CommandListMap.begin(); @@ -913,9 +914,11 @@ ur_result_t urQueueFinish( } Queue->Context->AsyncPool.cleanupPoolsForQueue(Queue); + std::shared_lock ContextLock(Queue->Context->Mutex); for (auto &Pool : Queue->Context->UsmPoolHandles) { Pool->cleanupPoolsForQueue(Queue); } + ContextLock.unlock(); return UR_RESULT_SUCCESS; }