https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66146
--- Comment #20 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Anthony Williams from comment #16) > Would it be worth ignoring pthread_once and using an implementation of > call_once based on Mike Burrows' algorithm? > > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2444.html That seems to work for pthread_once but not std::call_once, due to this assumption: The number of pthread_once_t variables in a programme is bounded and can be counted in an instance of type T without overflow. If T is 32-bits, this implementation requires that the number of pthread_once_t variables in a programme not exceed 2**31-3. (Recall that pthread_once_t variables are intended to have static storage class, so it would be remarkable for such a huge number to exist.) Nothing prevents an unbounded number of std::once_flag objects in C++: #include <mutex> int main() { while (true) { std::once_flag f; std::call_once(f, [](){}); } }