diff --git a/projects/clr/rocclr/thread/monitor.cpp b/projects/clr/rocclr/thread/monitor.cpp index dbb7949755..9c77f961dc 100644 --- a/projects/clr/rocclr/thread/monitor.cpp +++ b/projects/clr/rocclr/thread/monitor.cpp @@ -205,6 +205,10 @@ void Monitor::finishUnlock() { return; } + // A StoreLoad barrier is required to make sure the onDeck_ store is published before + // the contendersList_ micro-lock check. + std::atomic_thread_fence(std::memory_order_seq_cst); + // We do not have an on-deck thread (semaphore == NULL). Return if // the contention list is empty or if the lock got acquired again. head = contendersList_; diff --git a/projects/clr/rocclr/thread/monitor.hpp b/projects/clr/rocclr/thread/monitor.hpp index 7581d13778..c89ec287aa 100644 --- a/projects/clr/rocclr/thread/monitor.hpp +++ b/projects/clr/rocclr/thread/monitor.hpp @@ -228,6 +228,11 @@ inline void Monitor::unlock() { while (!contendersList_.compare_exchange_weak(ptr, ptr & ~kLockBit, std::memory_order_acq_rel, std::memory_order_acquire)) ; + + // A StoreLoad barrier is required to make sure future loads do not happen before the + // contendersList_ store is published. + std::atomic_thread_fence(std::memory_order_seq_cst); + // // We succeeded the CAS from locked to unlocked. // This is the end of the critical region.