public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/97949] New: Recursive calls of std::call_once together with cout leads to deadlock under mingw64
@ 2020-11-23 12:35 fiesh at zefix dot tv
  2020-11-23 15:48 ` [Bug libstdc++/97949] " redi at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: fiesh at zefix dot tv @ 2020-11-23 12:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97949
           Summary: Recursive calls of std::call_once together with cout
                    leads to deadlock under mingw64
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fiesh at zefix dot tv
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: x86_64-w64-mingw32.static

The following code locks under Windows 10:

-----------------------------
#include <chrono>
#include <iostream>
#include <mutex>
#include <thread>

std::once_flag flag0;
std::once_flag flag1;

void innerDoOnce()
{
        std::call_once(flag0, []() {
                using namespace std::chrono_literals;
                std::cout << "innerDoOnce() called...\n";
                std::this_thread::sleep_for(1s);
        });
}

void outerDoOnce()
{
        std::call_once(flag1, []() {
                std::cout << "outerDoOnce() called...\n";
                innerDoOnce();
        });
}

int main()
{
        std::thread t0(innerDoOnce);
        std::thread t1(innerDoOnce);
        std::thread t2(outerDoOnce);
        std::thread t3(outerDoOnce);
        t0.join();
        t1.join();
        t2.join();
        t3.join();
        std::cout << "aggi\n";
}
---------------------

Removing the `std::cout` calls seems to make the issue go away.

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

* [Bug libstdc++/97949] Recursive calls of std::call_once together with cout leads to deadlock under mingw64
  2020-11-23 12:35 [Bug libstdc++/97949] New: Recursive calls of std::call_once together with cout leads to deadlock under mingw64 fiesh at zefix dot tv
@ 2020-11-23 15:48 ` redi at gcc dot gnu.org
  2020-11-23 20:44 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2020-11-23 15:48 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-11-23
     Ever confirmed|0                           |1

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

* [Bug libstdc++/97949] Recursive calls of std::call_once together with cout leads to deadlock under mingw64
  2020-11-23 12:35 [Bug libstdc++/97949] New: Recursive calls of std::call_once together with cout leads to deadlock under mingw64 fiesh at zefix dot tv
  2020-11-23 15:48 ` [Bug libstdc++/97949] " redi at gcc dot gnu.org
@ 2020-11-23 20:44 ` redi at gcc dot gnu.org
  2020-11-23 21:03 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2020-11-23 20:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This isn't specific to mingw, it's a bug in the std::call_once implementation
for non-TLS targets. t2 runs outerDoOnce() and tries to acquire a mutex lock
before running innerDoOnce(), but that mutex is held by t3 while it waits to
try to run outerDoOnce(). t3 won't proceed until t2 finishes, which is blocked
by t3.

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

* [Bug libstdc++/97949] Recursive calls of std::call_once together with cout leads to deadlock under mingw64
  2020-11-23 12:35 [Bug libstdc++/97949] New: Recursive calls of std::call_once together with cout leads to deadlock under mingw64 fiesh at zefix dot tv
  2020-11-23 15:48 ` [Bug libstdc++/97949] " redi at gcc dot gnu.org
  2020-11-23 20:44 ` redi at gcc dot gnu.org
@ 2020-11-23 21:03 ` redi at gcc dot gnu.org
  2021-03-11 21:22 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2020-11-23 21:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Oh, and I think the cout calls just slow things down and introduce some
serialization (in stdio) so that the threads run concurrently.

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

* [Bug libstdc++/97949] Recursive calls of std::call_once together with cout leads to deadlock under mingw64
  2020-11-23 12:35 [Bug libstdc++/97949] New: Recursive calls of std::call_once together with cout leads to deadlock under mingw64 fiesh at zefix dot tv
                   ` (2 preceding siblings ...)
  2020-11-23 21:03 ` redi at gcc dot gnu.org
@ 2021-03-11 21:22 ` redi at gcc dot gnu.org
  2022-05-06  8:30 ` jakub at gcc dot gnu.org
  2022-05-06 12:32 ` redi at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-03-11 21:22 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0

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

* [Bug libstdc++/97949] Recursive calls of std::call_once together with cout leads to deadlock under mingw64
  2020-11-23 12:35 [Bug libstdc++/97949] New: Recursive calls of std::call_once together with cout leads to deadlock under mingw64 fiesh at zefix dot tv
                   ` (3 preceding siblings ...)
  2021-03-11 21:22 ` redi at gcc dot gnu.org
@ 2022-05-06  8:30 ` jakub at gcc dot gnu.org
  2022-05-06 12:32 ` redi at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-05-06  8:30 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|12.0                        |12.2

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 12.1 is being released, retargeting bugs to GCC 12.2.

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

* [Bug libstdc++/97949] Recursive calls of std::call_once together with cout leads to deadlock under mingw64
  2020-11-23 12:35 [Bug libstdc++/97949] New: Recursive calls of std::call_once together with cout leads to deadlock under mingw64 fiesh at zefix dot tv
                   ` (4 preceding siblings ...)
  2022-05-06  8:30 ` jakub at gcc dot gnu.org
@ 2022-05-06 12:32 ` redi at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2022-05-06 12:32 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|12.2                        |---

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This won't be fixed for 12.x

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

end of thread, other threads:[~2022-05-06 12:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-23 12:35 [Bug libstdc++/97949] New: Recursive calls of std::call_once together with cout leads to deadlock under mingw64 fiesh at zefix dot tv
2020-11-23 15:48 ` [Bug libstdc++/97949] " redi at gcc dot gnu.org
2020-11-23 20:44 ` redi at gcc dot gnu.org
2020-11-23 21:03 ` redi at gcc dot gnu.org
2021-03-11 21:22 ` redi at gcc dot gnu.org
2022-05-06  8:30 ` jakub at gcc dot gnu.org
2022-05-06 12:32 ` redi 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).