* [PATCH] Strengthen memory memory order for atomic<T>::wait/notify
@ 2022-01-16 1:47 Thomas Rodgers
2022-01-16 20:30 ` Jonathan Wakely
0 siblings, 1 reply; 3+ messages in thread
From: Thomas Rodgers @ 2022-01-16 1:47 UTC (permalink / raw)
To: libstdc++, gcc Patches
[-- Attachment #1: Type: text/plain, Size: 165 bytes --]
This patch updates the memory order of atomic accesses to the waiter's
count to match libc++'s usage. It should be backported to GCC11.
Tested x86_64-pc-linux-gnu.
[-- Attachment #2: 0001-Strengthen-memory-memory-order-for-atomic-T-wait-not.patch --]
[-- Type: text/x-patch, Size: 2023 bytes --]
From f5ed7674f86283db4f4ff49a2cc65d4f852413a1 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers <rodgert@twrodgers.com>
Date: Sat, 15 Jan 2022 17:40:49 -0800
Subject: [PATCH] Strengthen memory memory order for atomic<T>::wait/notify
This matches the memory order in libc++.
libstdc++-v3/ChangeLog:
* libstdc++-v3/include/bits/atomic_wait.h: Change memory order
from Acquire/Release with relaxed loads to SeqCst+Release for
accesses to the waiter's count.
---
libstdc++-v3/include/bits/atomic_wait.h | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h
index 05cf0013d2a..d7de0d7eb9e 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -209,18 +209,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void
_M_enter_wait() noexcept
- { __atomic_fetch_add(&_M_wait, 1, __ATOMIC_ACQ_REL); }
+ { __atomic_fetch_add(&_M_wait, 1, __ATOMIC_SEQ_CST); }
void
_M_leave_wait() noexcept
- { __atomic_fetch_sub(&_M_wait, 1, __ATOMIC_ACQ_REL); }
+ { __atomic_fetch_sub(&_M_wait, 1, __ATOMIC_RELEASE); }
bool
_M_waiting() const noexcept
{
__platform_wait_t __res;
- __atomic_load(&_M_wait, &__res, __ATOMIC_ACQUIRE);
- return __res > 0;
+ __atomic_load(&_M_wait, &__res, __ATOMIC_SEQ_CST);
+ return __res != 0;
}
void
@@ -258,7 +258,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__platform_wait(__addr, __old);
#else
__platform_wait_t __val;
- __atomic_load(__addr, &__val, __ATOMIC_RELAXED);
+ __atomic_load(__addr, &__val, __ATOMIC_SEQ_CST);
if (__val == __old)
{
lock_guard<mutex> __l(_M_mtx);
@@ -309,7 +309,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
if (_M_laundered())
{
- __atomic_fetch_add(_M_addr, 1, __ATOMIC_ACQ_REL);
+ __atomic_fetch_add(_M_addr, 1, __ATOMIC_SEQ_CST);
__all = true;
}
_M_w._M_notify(_M_addr, __all, __bare);
--
2.31.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Strengthen memory memory order for atomic<T>::wait/notify
2022-01-16 1:47 [PATCH] Strengthen memory memory order for atomic<T>::wait/notify Thomas Rodgers
@ 2022-01-16 20:30 ` Jonathan Wakely
2022-02-01 17:17 ` Thomas Rodgers
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2022-01-16 20:30 UTC (permalink / raw)
To: Thomas Rodgers; +Cc: libstdc++, gcc Patches
On Sun, 16 Jan 2022 at 01:48, Thomas Rodgers via Libstdc++ <
libstdc++@gcc.gnu.org> wrote:
> This patch updates the memory order of atomic accesses to the waiter's
> count to match libc++'s usage. It should be backported to GCC11.
>
The commit subject line says "memory memory order", OK for trunk and gcc-11
with that fixed.
> Tested x86_64-pc-linux-gnu.
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Strengthen memory memory order for atomic<T>::wait/notify
2022-01-16 20:30 ` Jonathan Wakely
@ 2022-02-01 17:17 ` Thomas Rodgers
0 siblings, 0 replies; 3+ messages in thread
From: Thomas Rodgers @ 2022-02-01 17:17 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: libstdc++, gcc Patches
Tested x86_64-pc-linux-gnu, committed to master.
Backported to GCC-11.
On Sun, Jan 16, 2022 at 12:31 PM Jonathan Wakely <jwakely@redhat.com> wrote:
>
>
> On Sun, 16 Jan 2022 at 01:48, Thomas Rodgers via Libstdc++ <
> libstdc++@gcc.gnu.org> wrote:
>
>> This patch updates the memory order of atomic accesses to the waiter's
>> count to match libc++'s usage. It should be backported to GCC11.
>>
>
> The commit subject line says "memory memory order", OK for trunk and
> gcc-11 with that fixed.
>
>
>> Tested x86_64-pc-linux-gnu.
>>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-01 17:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-16 1:47 [PATCH] Strengthen memory memory order for atomic<T>::wait/notify Thomas Rodgers
2022-01-16 20:30 ` Jonathan Wakely
2022-02-01 17:17 ` Thomas Rodgers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).