From: Jonathan Wakely <jwakely@redhat.com>
To: Thomas Rodgers <rodgert@appliantology.com>
Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org,
trodgers@redhat.com, Thomas Rodgers <rodgert@twrodgers.com>
Subject: Re: [PATCH] libstdc++: Fix wrong thread waking on notify [PR100334]
Date: Fri, 14 May 2021 18:09:51 +0100 [thread overview]
Message-ID: <YJ6u30NVKg4Haub9@redhat.com> (raw)
In-Reply-To: <20210514015436.111757-1-rodgert@appliantology.com>
On 13/05/21 18:54 -0700, Thomas Rodgers wrote:
>From: Thomas Rodgers <rodgert@twrodgers.com>
>
>Please ignore the previous patch. This one removes the need to carry any
>extra state in the case of a 'laundered' atomic wait.
>
>libstdc++/ChangeLog:
> * include/bits/atomic_wait.h (__waiter::_M_do_wait_v): loop
> until value change observed.
> (__waiter_base::_M_laundered): New member function.
> (__watier_base::_M_notify): Check _M_laundered() to determine
> whether to wake one or all.
> (__detail::__atomic_compare): Return true if call to
> __builtin_memcmp() == 0.
> (__waiter_base::_S_do_spin_v): Adjust predicate.
> * testsuite/29_atomics/atomic/wait_notify/100334.cc: New
> test.
>---
> libstdc++-v3/include/bits/atomic_wait.h | 28 ++++--
> .../29_atomics/atomic/wait_notify/100334.cc | 94 +++++++++++++++++++
> 2 files changed, 114 insertions(+), 8 deletions(-)
> create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/wait_notify/100334.cc
>
>diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h
>index 984ed70f16c..07bb744d822 100644
>--- a/libstdc++-v3/include/bits/atomic_wait.h
>+++ b/libstdc++-v3/include/bits/atomic_wait.h
>@@ -181,11 +181,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> return false;
> }
>
>+ // return true if equal
> template<typename _Tp>
> bool __atomic_compare(const _Tp& __a, const _Tp& __b)
> {
> // TODO make this do the correct padding bit ignoring comparison
>- return __builtin_memcmp(&__a, &__b, sizeof(_Tp)) != 0;
>+ return __builtin_memcmp(&__a, &__b, sizeof(_Tp)) == 0;
> }
>
> struct __waiter_pool_base
>@@ -300,14 +301,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> explicit __waiter_base(const _Up* __addr) noexcept
> : _M_w(_S_for(__addr))
> , _M_addr(_S_wait_addr(__addr, &_M_w._M_ver))
>- {
>- }
>+ { }
>+
>+ bool
>+ _M_laundered() const
>+ { return _M_addr == &_M_w._M_ver; }
>
> void
> _M_notify(bool __all, bool __bare = false)
> {
>- if (_M_addr == &_M_w._M_ver)
>- __atomic_fetch_add(_M_addr, 1, __ATOMIC_ACQ_REL);
>+ if (_M_laundered())
>+ {
>+ __atomic_fetch_add(_M_addr, 1, __ATOMIC_ACQ_REL);
Please mention this increment in the changelog.
OK for trunk and gcc-11 with that change, thanks.
next prev parent reply other threads:[~2021-05-14 17:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-03 16:43 Thomas Rodgers
2021-05-10 18:21 ` Jonathan Wakely
2021-05-13 23:35 ` Thomas Rodgers
2021-05-14 1:54 ` Thomas Rodgers
2021-05-14 17:09 ` Jonathan Wakely [this message]
2021-05-17 16:43 ` Jonathan Wakely
2021-05-17 19:08 ` Thomas Rodgers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YJ6u30NVKg4Haub9@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
--cc=rodgert@appliantology.com \
--cc=rodgert@twrodgers.com \
--cc=trodgers@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).