https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96817
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Last reconfirmed| |2020-08-27 Status|UNCONFIRMED |NEW --- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> --- Something like this should work with the latest glibc: --- a/libstdc++-v3/libsupc++/guard.cc +++ b/libstdc++-v3/libsupc++/guard.cc @@ -252,7 +252,22 @@ namespace __cxxabiv1 # ifdef _GLIBCXX_USE_FUTEX // If __atomic_* and futex syscall are supported, don't use any global // mutex. +#if __has_include(<sys/single_threaded.h>) + // Prefer to rely on __libc_single_threaded instead of __gthread_active_p + if (__libc_single_threaded) + { + int *gi = (int *) (void *) g; + if (*gi == 0) + { + *gi = _GLIBCXX_GUARD_PENDING_BIT; + return 1; + } + else + throw_recursive_init_exception(); + } +#else if (__gthread_active_p ()) +#endif { int *gi = (int *) (void *) g; const int guard_bit = _GLIBCXX_GUARD_BIT; @@ -390,7 +405,17 @@ namespace __cxxabiv1 #ifdef _GLIBCXX_USE_FUTEX // If __atomic_* and futex syscall are supported, don't use any global // mutex. +#if __has_include(<sys/single_threaded.h>) + // Prefer to rely on __libc_single_threaded instead of __gthread_active_p + if (__libc_single_threaded) + { + int *gi = (int *) (void *) g; + *gi = _GLIBCXX_GUARD_BIT; + return; + } +#else if (__gthread_active_p ()) +#endif { int *gi = (int *) (void *) g; const int guard_bit = _GLIBCXX_GUARD_BIT;