[Bug libstdc++/97949] New: Recursive calls of std::call_once together with cout leads to deadlock under mingw64

fiesh at zefix dot tv gcc-bugzilla@gcc.gnu.org
Mon Nov 23 12:35:59 GMT 2020


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.


More information about the Gcc-bugs mailing list