From 45b75013ec39eef2e1922f4e798e05ab2b188198 Mon Sep 17 00:00:00 2001 From: "Sang, Tao" Date: Wed, 23 Apr 2025 14:34:53 -0400 Subject: [PATCH] SWDEV-516050 - Fix monitor hang in OCL (#75) Fix monitor hang in cts integer_ops. Improve notify(). Won't affect notifyAll() and Hip in direct dispatch mode. Change-Id: I95a458358e1cab9c76aefde117db09cdbd1fd3af [ROCm/clr commit: 78f92901d8643b71ecca1cbb3883deb3444e0129] --- projects/clr/rocclr/thread/monitor.hpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/projects/clr/rocclr/thread/monitor.hpp b/projects/clr/rocclr/thread/monitor.hpp index 179bf6cb77..2c6b7f6a30 100644 --- a/projects/clr/rocclr/thread/monitor.hpp +++ b/projects/clr/rocclr/thread/monitor.hpp @@ -223,9 +223,7 @@ class Monitor { // fast path c = 0; while (c < maxCount_ && - (notifyState_.load(std::memory_order_acquire) != notifyState::allNotified && - !notifyState_.compare_exchange_weak(expextedNotifyState, notifyState::notNotified, - std::memory_order_acq_rel, std::memory_order_acquire))) { + (notifyState_.load(std::memory_order_acquire) == notifyState::notNotified)) { // First, be SMT friendly if (c < maxReadSpinIter_) { Os::spinPause(); @@ -261,10 +259,8 @@ class Monitor { // the mutex is locked again before exiting... lk.release(); // Release the ownership so that the caller should unlock the mutex if (waits_.fetch_sub(1, std::memory_order_acq_rel) == 1) { - if (notifyState_.load(std::memory_order_acquire) == notifyState::allNotified) { - // No waiter indicates that notifyAll() processing has ended - notifyState_.store(notifyState::notNotified, std::memory_order_release); - } + // No waiter indicates that notify() or notifyAll() processing has ended + notifyState_.store(notifyState::notNotified, std::memory_order_release); } }