[Bug libstdc++/104495] New: call_once hangs in call after exceptional call

f.heckenbach@fh-soft.de gcc-bugzilla@gcc.gnu.org
Thu Feb 10 22:35:19 GMT 2022


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

            Bug ID: 104495
           Summary: call_once hangs in call after exceptional call
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: f.heckenbach@fh-soft.de
  Target Milestone: ---

% cat test.cpp
#include <iostream>
#include <thread>
#include <mutex>

std::once_flag flag2;

void may_throw_function(bool do_throw)
{
  if (do_throw) {
    std::cout << "throw: call_once will retry\n";
    throw std::exception();
  }
  std::cout << "Didn't throw, call_once will not attempt again\n";
}

void do_once(bool do_throw)
{
  try {
    std::call_once(flag2, may_throw_function, do_throw);
  }
  catch (...) {
  }
}

int main()
{
    do_once (true);
    do_once (false);
}
% g++ test.cpp -pthread
% ./a.out
throw: call_once will retry
[hangs]

This is a simplified version of the example from
https://en.cppreference.com/w/cpp/thread/call_once -- the full example also
hangs.

My actual use case is a bit different, but it seems any call after an exception
call hangs; that's all that seems relevant.


More information about the Gcc-bugs mailing list