public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/106183] std::atomic::wait might fail to be unblocked by notify_one/all on platforms without platform_wait() Date: Thu, 04 Aug 2022 12:30:00 +0000 [thread overview] Message-ID: <bug-106183-4-hJhp4KUo2U@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-106183-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106183 --- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>: https://gcc.gnu.org/g:af98cb88eb4be6a1668ddf966e975149bf8610b1 commit r13-1957-gaf98cb88eb4be6a1668ddf966e975149bf8610b1 Author: Jonathan Wakely <jwakely@redhat.com> Date: Thu Jul 28 16:15:58 2022 +0100 libstdc++: Unblock atomic wait on non-futex platforms [PR106183] When using a mutex and condition variable, the notifying thread needs to increment _M_ver while holding the mutex lock, and the waiting thread needs to re-check after locking the mutex. This avoids a missed notification as described in the PR. By moving the increment of _M_ver to the base _M_notify we can make the use of the mutex local to the use of the condition variable, and simplify the code a little. We can use a relaxed store because the mutex already provides sequential consistency. Also we don't need to check whether __addr == &_M_ver because we know that's always true for platforms that use a condition variable, and so we also know that we always need to use notify_all() not notify_one(). Reviewed-by: Thomas Rodgers <trodgers@redhat.com> libstdc++-v3/ChangeLog: PR libstdc++/106183 * include/bits/atomic_wait.h (__waiter_pool_base::_M_notify): Move increment of _M_ver here. [!_GLIBCXX_HAVE_PLATFORM_WAIT]: Lock mutex around increment. Use relaxed memory order and always notify all waiters. (__waiter_base::_M_do_wait) [!_GLIBCXX_HAVE_PLATFORM_WAIT]: Check value again after locking mutex. (__waiter_base::_M_notify): Remove increment of _M_ver.
next prev parent reply other threads:[~2022-08-04 12:30 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-07-04 13:55 [Bug libstdc++/106183] New: std::atomic::wait might deadlock " lewissbaker.opensource at gmail dot com 2022-07-06 0:04 ` [Bug libstdc++/106183] std::atomic::wait might fail to be unblocked by notify_one/all " rodgertq at gcc dot gnu.org 2022-07-15 12:45 ` tedlion_tang at foxmail dot com 2022-07-15 14:36 ` redi at gcc dot gnu.org 2022-07-25 13:51 ` anthony.ajw at gmail dot com 2022-08-01 11:38 ` redi at gcc dot gnu.org 2022-08-04 12:30 ` cvs-commit at gcc dot gnu.org [this message] 2022-08-04 12:42 ` redi at gcc dot gnu.org 2023-01-16 17:43 ` redi at gcc dot gnu.org 2023-01-16 17:46 ` cvs-commit at gcc dot gnu.org 2023-01-17 6:59 ` i.nixman at autistici dot org 2023-01-18 11:29 ` cvs-commit at gcc dot gnu.org 2023-01-18 11:33 ` redi at gcc dot gnu.org
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=bug-106183-4-hJhp4KUo2U@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /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: linkBe 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).