Skip to content

Commit 7eee446

Browse files
authored
[SYCL][CUDA] Use context mutex in refcount inc/dec (#6577)
context wasn't using its mutex when incrementing/decrementing the ref count, even though multiple threads may attempt this at the same time in multithreaded applications such as in assert_in_simultaneously_multiple_tus.cpp. This may fix #6463 but I can't be sure of this because I can't reproduce flaky CI test failures in #6463 locally. Signed-off-by: JackAKirk <jack.kirk@codeplay.com>
1 parent 3d506a3 commit 7eee446

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

sycl/plugins/cuda/pi_cuda.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,15 @@ struct _pi_context {
201201

202202
bool is_primary() const noexcept { return kind_ == kind::primary; }
203203

204-
pi_uint32 increment_reference_count() noexcept { return ++refCount_; }
204+
pi_uint32 increment_reference_count() noexcept {
205+
std::lock_guard<std::mutex> guard(mutex_);
206+
return ++refCount_;
207+
}
205208

206-
pi_uint32 decrement_reference_count() noexcept { return --refCount_; }
209+
pi_uint32 decrement_reference_count() noexcept {
210+
std::lock_guard<std::mutex> guard(mutex_);
211+
return --refCount_;
212+
}
207213

208214
pi_uint32 get_reference_count() const noexcept { return refCount_; }
209215

0 commit comments

Comments
 (0)