From 30a14a8a05d0fb0f72ec11d480c20225e8abbccb Mon Sep 17 00:00:00 2001 From: Ioannis Assiouras <38722728+iassiour@users.noreply.github.com> Date: Mon, 20 Oct 2025 17:15:56 +0100 Subject: [PATCH] SWDEV-559166 - Fix potential data race in ReferenceCountedObject::release() (#1388) Use fetch_sub(std::memory_order_acq_rel) on release so the destroying thread acquires prior writes. --- projects/clr/rocclr/platform/runtime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/clr/rocclr/platform/runtime.cpp b/projects/clr/rocclr/platform/runtime.cpp index 4ad1852e34..c3a1aed75f 100644 --- a/projects/clr/rocclr/platform/runtime.cpp +++ b/projects/clr/rocclr/platform/runtime.cpp @@ -134,7 +134,7 @@ uint ReferenceCountedObject::retain() { } uint ReferenceCountedObject::release() { - uint newCount = referenceCount_.fetch_sub(1, std::memory_order_relaxed) - 1; + uint newCount = referenceCount_.fetch_sub(1, std::memory_order_acq_rel) - 1; if (newCount == 0) { if (terminate()) { // The destructor should be called with a count==1 for the last thread