libstdc++: Strengthen memory order for atomic<T>::wait/notify

Message ID CAMmuTO_ofvnWAja1M9NSNrgYcHSFAea3quwPS=uFm6Wmo2fepg@mail.gmail.com
State Committed
Headers
Series libstdc++: Strengthen memory order for atomic<T>::wait/notify |

Commit Message

Thomas Rodgers Feb. 9, 2022, 5:35 p.m. UTC
  This patch changes the memory order used in the spin wait code to match
that of libc++.
  

Comments

Jonathan Wakely Feb. 9, 2022, 8:36 p.m. UTC | #1
On Wed, 9 Feb 2022 at 17:35, Thomas Rodgers via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> This patch changes the memory order used in the spin wait code to match
> that of libc++.

OK for trunk (and gcc-11 if needed).
  
Thomas Rodgers Feb. 10, 2022, 6:22 p.m. UTC | #2
Committed to trunk, backported to gcc-11.

On Wed, Feb 9, 2022 at 12:37 PM Jonathan Wakely <jwakely@redhat.com> wrote:

> On Wed, 9 Feb 2022 at 17:35, Thomas Rodgers via Libstdc++
> <libstdc++@gcc.gnu.org> wrote:
> >
> > This patch changes the memory order used in the spin wait code to match
> > that of libc++.
>
> OK for trunk (and gcc-11 if needed).
>
>
  

Patch

From 92caa08b272520ec4a272b302b37d8fb47afb2ab Mon Sep 17 00:00:00 2001
From: Thomas Rodgers <rodgert@appliantology.com>
Date: Wed, 9 Feb 2022 09:26:00 -0800
Subject: [PATCH] libstdc++: Strengthen memory order for atomic<T>::wait/notify
 (spinning)

This patch changes the memory order used in the spin wait code to match
that of libc++.

libstdc++-v3/ChangeLog:
	* includ/bits/atomic_wait.h (__waiter_base::_S_do_spin,
	__waiter_base::_S_do_spin_v): Change memory order from relaxed
	to acquire.
---
 libstdc++-v3/include/bits/atomic_wait.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h
index 6ce7f9343cf..125b1cad886 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -332,7 +332,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	      }
 	    else
 	      {
-		__atomic_load(__addr, &__val, __ATOMIC_RELAXED);
+		__atomic_load(__addr, &__val, __ATOMIC_ACQUIRE);
 	      }
 	    return __atomic_spin(__pred, __spin);
 	  }
@@ -353,7 +353,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		     __platform_wait_t& __val,
 		     _Spin __spin = _Spin{ })
 	  {
-	    __atomic_load(__addr, &__val, __ATOMIC_RELAXED);
+	    __atomic_load(__addr, &__val, __ATOMIC_ACQUIRE);
 	    return __atomic_spin(__pred, __spin);
 	  }
 
-- 
2.34.1