public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Thomas Rodgers <rodgert@appliantology.com>
To: libstdc++ <libstdc++@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Cc: Thomas Rodgers <trodgers@redhat.com>
Subject: Re: [PATCH] Adjust wait logic to limit spurious evalution of wait predicate.
Date: Sun, 24 May 2020 19:17:24 -0700	[thread overview]
Message-ID: <18CE5491-6049-430B-85A3-284117B604E4@appliantology.com> (raw)
In-Reply-To: <32A8D493-8AA8-47E6-BDDB-65CA10D3D357@appliantology.com>

[-- Attachment #1: Type: text/plain, Size: 28 bytes --]

And this time, with patch.


[-- Attachment #2: wake_up_fix.patch --]
[-- Type: application/octet-stream, Size: 1509 bytes --]

commit fe8959f61a0945662c2521b3ea47fbc2b751e881
Author: Thomas Rodgers <rodgert@appliantology.com>
Date:   Sun May 24 15:00:13 2020 -0700

    Adjust wait logic to limit spurious evalution of wait predicate.
    
            * include/bits/atomic_wait.h (__waiters::_M_do_wait): adjust wakeup
              logic.

diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h
index 92c1e2526ed..cce11ae1cf5 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -138,24 +138,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       }
 
       void
-      _M_do_wait(__platform_wait_t __version) noexcept
+      _M_do_wait(__platform_wait_t __old) noexcept
       {
-#ifdef _GLIBCXX_HAVE_LINUX_FUTEX
-	__platform_wait(&_M_ver, __version);
-#else
-	__platform_wait_t __cur = 0;
-	while (__cur <= __version)
+	__platform_wait_t __cur;
+	__atomic_load(&_M_ver, &__cur, __ATOMIC_ACQUIRE);
+	while (__cur == __old)
 	  {
+#ifdef _GLIBCXX_HAVE_LINUX_FUTEX
+	    __platform_wait(&_M_ver, __cur);
+#else
 	    __waiters::__lock_t __l(_M_mtx);
 	    auto __e = __gthread_cond_wait(&_M_cv, __l.mutex()->native_handle());
 	    if (__e)
 	      std::terminate();
-	    __platform_wait_t __last = __cur;
-	    __atomic_load(&_M_ver, &__cur, __ATOMIC_ACQUIRE);
-	    if (__cur < __last)
-	      break; // break the loop if version overflows
-	  }
 #endif
+	    __atomic_load(&_M_ver, &__cur, __ATOMIC_ACQUIRE);
+	  }
       }
 
       __platform_wait_t

[-- Attachment #3: Type: text/plain, Size: 171 bytes --]



> On May 24, 2020, at 3:06 PM, Thomas Rodgers <rodgert@appliantology.com> wrote:
> 
> 	* include/bits/atomic_wait.h (__waiters::_M_do_wait): adjust wakeup logic.


      reply	other threads:[~2020-05-25  2:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-24 22:06 Thomas Rodgers
2020-05-25  2:17 ` Thomas Rodgers [this message]

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=18CE5491-6049-430B-85A3-284117B604E4@appliantology.com \
    --to=rodgert@appliantology.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    --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).