Skip to content

Commit bd5893a

Browse files
[SYCL] Fix hang in deallocateStreams function (#2796)
This patch fixes hang caused by data race in `scheduler.cpp`'s `deallocateStreams` function: data of `StreamsToDeallocate` vector is corrupted by another thread, and due to this, it was a hang in `Scheduler::deallocateStreamBuffers` function when `StreamBuffersPool[Impl]` had been being deleted.
1 parent b54132b commit bd5893a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

sycl/source/detail/scheduler/scheduler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,13 @@ void Scheduler::enqueueLeavesOfReqUnlocked(const Requirement *const Req) {
276276
void Scheduler::allocateStreamBuffers(stream_impl *Impl,
277277
size_t StreamBufferSize,
278278
size_t FlushBufferSize) {
279-
std::lock_guard<std::mutex> lock(StreamBuffersPoolMutex);
279+
std::lock_guard<std::recursive_mutex> lock(StreamBuffersPoolMutex);
280280
StreamBuffersPool.insert(
281281
{Impl, new StreamBuffers(StreamBufferSize, FlushBufferSize)});
282282
}
283283

284284
void Scheduler::deallocateStreamBuffers(stream_impl *Impl) {
285-
std::lock_guard<std::mutex> lock(StreamBuffersPoolMutex);
285+
std::lock_guard<std::recursive_mutex> lock(StreamBuffersPoolMutex);
286286
delete StreamBuffersPool[Impl];
287287
StreamBuffersPool.erase(Impl);
288288
}
@@ -302,7 +302,7 @@ Scheduler::~Scheduler() {
302302
// the kernel. Otherwise resources for stream will not be released, issue a
303303
// warning in this case.
304304
if (pi::trace(pi::TraceLevel::PI_TRACE_BASIC)) {
305-
std::lock_guard<std::mutex> lock(StreamBuffersPoolMutex);
305+
std::lock_guard<std::recursive_mutex> lock(StreamBuffersPoolMutex);
306306
if (!StreamBuffersPool.empty())
307307
fprintf(
308308
stderr,

sycl/source/detail/scheduler/scheduler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ class Scheduler {
766766
friend class stream_impl;
767767

768768
// Protects stream buffers pool
769-
std::mutex StreamBuffersPoolMutex;
769+
std::recursive_mutex StreamBuffersPoolMutex;
770770

771771
// We need to store a pointer to the structure with stream buffers because we
772772
// want to avoid a situation when buffers are destructed during destruction of

0 commit comments

Comments
 (0)