public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/100806] New: deadlock in std::counting_semaphore
@ 2021-05-27 21:21 gatroubo at squizzy dot net
  2021-05-28 18:08 ` [Bug libstdc++/100806] " rodgertq at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: gatroubo at squizzy dot net @ 2021-05-27 21:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100806

            Bug ID: 100806
           Summary: deadlock in std::counting_semaphore
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gatroubo at squizzy dot net
  Target Milestone: ---

Hi,

there seems to be some sort of deadlock in std::counting_semaphore. In the
following test program, I create 10 threads, each thread tries to acquire a
semaphore (initial value 4), waits 100ms, and then releases the semaphore:

https://wandbox.org/permlink/Zt3d4EC5vNOXtr9W

Most of the time, the program seems to be in a deadlock after 5 threads
acquired/released the semaphore. When I compile and run the same code with
clang 11.1 I get the expected behavoir (all 10 threads aquire/release the
semaphore and the program exits successfully):

https://wandbox.org/permlink/XjQaoyy9C6uiDYlo

Thanks for your effort to create such a great tool!
-Tobias

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/100806] deadlock in std::counting_semaphore
  2021-05-27 21:21 [Bug libstdc++/100806] New: deadlock in std::counting_semaphore gatroubo at squizzy dot net
@ 2021-05-28 18:08 ` rodgertq at gcc dot gnu.org
  2021-06-16 18:45 ` rodgertq at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rodgertq at gcc dot gnu.org @ 2021-05-28 18:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100806

Thomas Rodgers <rodgertq at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-05-28
           Assignee|unassigned at gcc dot gnu.org      |rodgertq at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1

--- Comment #1 from Thomas Rodgers <rodgertq at gcc dot gnu.org> ---
This is almost certainly a duplicate of
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100334

Which is fixed on master with a backport to releases/gcc-11 but was broken in
GCC 11.1

Will confirm, thanks!

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/100806] deadlock in std::counting_semaphore
  2021-05-27 21:21 [Bug libstdc++/100806] New: deadlock in std::counting_semaphore gatroubo at squizzy dot net
  2021-05-28 18:08 ` [Bug libstdc++/100806] " rodgertq at gcc dot gnu.org
@ 2021-06-16 18:45 ` rodgertq at gcc dot gnu.org
  2021-06-22 18:07 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rodgertq at gcc dot gnu.org @ 2021-06-16 18:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100806

--- Comment #2 from Thomas Rodgers <rodgertq at gcc dot gnu.org> ---
I have confirmed that this is new issue, not related to PR100334.

When there are waiting threads and the semaphore attempts to release one of
the waiting threads, the FUTEX_WAKE syscall's return indicates that 1 thread is
woken, as expected, but it is unclear to me why there is no forward progress at
that point.

I have replaced the algorithm with a simplified version (similar to what is in
libc++) and observe the same result. Further investigation is required. I have
submitted an interim patch that forces wake all which appears to address the
issue.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/100806] deadlock in std::counting_semaphore
  2021-05-27 21:21 [Bug libstdc++/100806] New: deadlock in std::counting_semaphore gatroubo at squizzy dot net
  2021-05-28 18:08 ` [Bug libstdc++/100806] " rodgertq at gcc dot gnu.org
  2021-06-16 18:45 ` rodgertq at gcc dot gnu.org
@ 2021-06-22 18:07 ` cvs-commit at gcc dot gnu.org
  2021-06-22 18:08 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-06-22 18:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100806

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Thomas Rodgers <rodgertq@gcc.gnu.org>:

https://gcc.gnu.org/g:e02840c1a92abecd211ffaf05b28329bcb534583

commit r12-1732-ge02840c1a92abecd211ffaf05b28329bcb534583
Author: Thomas Rodgers <rodgert@appliantology.com>
Date:   Tue Jun 22 10:59:07 2021 -0700

    libstdc++: Fix for deadlock in std::counting_semaphore [PR100806]

    libstdc++-v3/ChangeLog:
            PR libstdc++/100806
            * include/bits/semaphore_base.h (__atomic_semaphore::_M_release):
            Force _M_release() to wake all waiting threads.
            * testsuite/30_threads/semaphore/100806.cc: New test.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/100806] deadlock in std::counting_semaphore
  2021-05-27 21:21 [Bug libstdc++/100806] New: deadlock in std::counting_semaphore gatroubo at squizzy dot net
                   ` (2 preceding siblings ...)
  2021-06-22 18:07 ` cvs-commit at gcc dot gnu.org
@ 2021-06-22 18:08 ` cvs-commit at gcc dot gnu.org
  2022-02-14 17:03 ` rodgertq at gcc dot gnu.org
  2022-12-24 21:14 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-06-22 18:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100806

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Thomas Rodgers
<rodgertq@gcc.gnu.org>:

https://gcc.gnu.org/g:c24384efbbaeeca3dbc53e7d1226a57bc16e9ad5

commit r11-8638-gc24384efbbaeeca3dbc53e7d1226a57bc16e9ad5
Author: Thomas Rodgers <rodgert@appliantology.com>
Date:   Tue Jun 22 10:59:07 2021 -0700

    libstdc++: Fix for deadlock in std::counting_semaphore [PR100806]

    libstdc++-v3/ChangeLog:
            PR libstdc++/100806
            * include/bits/semaphore_base.h (__atomic_semaphore::_M_release):
            Force _M_release() to wake all waiting threads.
            * testsuite/30_threads/semaphore/100806.cc: New test.

    (cherry picked from commit e02840c1a92abecd211ffaf05b28329bcb534583)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/100806] deadlock in std::counting_semaphore
  2021-05-27 21:21 [Bug libstdc++/100806] New: deadlock in std::counting_semaphore gatroubo at squizzy dot net
                   ` (3 preceding siblings ...)
  2021-06-22 18:08 ` cvs-commit at gcc dot gnu.org
@ 2022-02-14 17:03 ` rodgertq at gcc dot gnu.org
  2022-12-24 21:14 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rodgertq at gcc dot gnu.org @ 2022-02-14 17:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100806

Thomas Rodgers <rodgertq at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Thomas Rodgers <rodgertq at gcc dot gnu.org> ---
I believe this has been fully resolved.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug libstdc++/100806] deadlock in std::counting_semaphore
  2021-05-27 21:21 [Bug libstdc++/100806] New: deadlock in std::counting_semaphore gatroubo at squizzy dot net
                   ` (4 preceding siblings ...)
  2022-02-14 17:03 ` rodgertq at gcc dot gnu.org
@ 2022-12-24 21:14 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-24 21:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100806

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.2

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-12-24 21:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-27 21:21 [Bug libstdc++/100806] New: deadlock in std::counting_semaphore gatroubo at squizzy dot net
2021-05-28 18:08 ` [Bug libstdc++/100806] " rodgertq at gcc dot gnu.org
2021-06-16 18:45 ` rodgertq at gcc dot gnu.org
2021-06-22 18:07 ` cvs-commit at gcc dot gnu.org
2021-06-22 18:08 ` cvs-commit at gcc dot gnu.org
2022-02-14 17:03 ` rodgertq at gcc dot gnu.org
2022-12-24 21:14 ` pinskia at gcc dot gnu.org

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).