public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "amy at amyspark dot me" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110016] New: [12/13/14] Possible miscodegen when inlining std::condition_variable::wait predicate causes deadlock Date: Sun, 28 May 2023 21:11:46 +0000 [thread overview] Message-ID: <bug-110016-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110016 Bug ID: 110016 Summary: [12/13/14] Possible miscodegen when inlining std::condition_variable::wait predicate causes deadlock Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: amy at amyspark dot me Target Milestone: --- Created attachment 55181 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55181&action=edit Minimum test case to reproduce the deadlock Hi all, This is to report a possible codegen issue when inlining a lambda predicate for std::condition_variable::wait. We've verified this to happen with the following versions: - g++-8 (Homebrew GCC 8.5.0) 8.5.0 - g++.exe (Rev6, Built by MSYS2 project) 13.1.0 (both UCRT64 and MINGW64) - g++ (Compiler-Explorer-Build-gcc-4579954f25020f0b39361ab6ec0c8876fda27041-binutils-2.40) 14.0.0 20230522 (experimental) The deadlock seems to happen with 100% certainty on GCC 12.2.1 if one enables ThreadSanitizer; otherwise it happens sporadically in CI. I packaged a reduced version of the test suite: https://godbolt.org/z/fj8rnrbo7, a copy of which you'll find attached to this report. Build with `-std=c++17 -pthread -O2 -fsanitize=thread`. In all cases, once the deadlock is hit (wait for ~3 seconds under GDB) the "finished" atomic boolean and the "workQueue" are correctly flagged as true and empty, respectively; however, the thread will still wait for the condition variable indefinitely. This can be easily worked around by blocking the inlining eg. turn the lambda into a std::bind instance. The complete code of the library where we reproduced this is available here: https://github.com/bad-alloc-heavy-industries/substrate/tree/375db811308ad7414771dbde9af4efa7aa393ca8. You can build it with `meson setup build -Dcpp_std=c++17 -Db_sanitize=thread` and run the test with `meson test -C build`.
next reply other threads:[~2023-05-28 21:11 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-28 21:11 amy at amyspark dot me [this message] 2023-05-28 21:44 ` [Bug libstdc++/110016] " pinskia at gcc dot gnu.org 2023-05-29 0:47 ` [Bug libstdc++/110016] " amy at amyspark dot me 2023-05-29 1:03 ` pinskia at gcc dot gnu.org 2023-05-29 1:05 ` pinskia at gcc dot gnu.org 2023-05-29 1:05 ` pinskia at gcc dot gnu.org 2023-05-29 1:20 ` pinskia at gcc dot gnu.org 2023-05-29 1:27 ` pinskia at gcc dot gnu.org 2023-05-29 1:34 ` pinskia at gcc dot gnu.org 2023-05-29 1:47 ` pinskia at gcc dot gnu.org 2023-05-29 6:43 ` pinskia at gcc dot gnu.org 2023-05-29 13:30 ` rachel at rachelmant dot com 2023-05-29 14:28 ` pinskia at gcc dot gnu.org 2023-05-29 15:15 ` pinskia at gcc dot gnu.org 2023-05-29 15:18 ` rachel at rachelmant dot com 2023-05-29 15:37 ` pinskia at gcc dot gnu.org 2023-05-29 20:38 ` 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-110016-4@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).