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

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