https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95989
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://sourceware.org/bugz
| |illa/show_bug.cgi?id=22635
--- Comment #13 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I'm testing this:
diff --git a/libgcc/gthr-posix.h b/libgcc/gthr-posix.h
index 965247602ac..0af84a781e5 100644
--- a/libgcc/gthr-posix.h
+++ b/libgcc/gthr-posix.h
@@ -684,7 +684,12 @@ __gthread_equal (__gthread_t __t1, __gthread_t __t2)
static inline __gthread_t
__gthread_self (void)
{
+#if __GLIBC_PREREQ(2, 27)
+ /* See PR libstdc++/95989 */
+ return pthread_self ();
+#else
return __gthrw_(pthread_self) ();
+#endif
}
static inline int
diff --git a/libstdc++-v3/include/std/thread b/libstdc++-v3/include/std/thread
index 0445ab1e319..2772dd3950e 100644
--- a/libstdc++-v3/include/std/thread
+++ b/libstdc++-v3/include/std/thread
@@ -364,13 +364,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
inline thread::id
get_id() noexcept
{
-#ifdef __GLIBC__
+#if defined __GLIBC__ && ! __GLIBC_PREREQ(2, 27)
// For the GNU C library pthread_self() is usable without linking to
- // libpthread.so but returns 0, so we cannot use it in single-threaded
- // programs, because this_thread::get_id() != thread::id{} must be true.
- // We know that pthread_t is an integral type in the GNU C library.
+ // libpthread, but prior to version 2.27 the version in libc returns 0,
+ // which breaks the invariant this_thread::get_id() != thread::id{}.
+ // We know that pthread_t is a scalar type in the GNU C library,
+ // so just use (__gthread_t)1 as the ID of the main (and only) thread.
if (!__gthread_active_p())
- return thread::id(1);
+ return thread::id((__gthread_t)1);
#endif
return thread::id(__gthread_self());
}