From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D0E0C3861973; Wed, 8 Jul 2020 15:36:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D0E0C3861973 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1594222576; bh=hOfyoU6JxT8d9h5/TugWNcR4MTaEs5yV1vqu6q+9LNY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TKa1v+U9Xqe72pP3L5GR+gfHRz5xa9bJMMVPPSCyoiFdndcuWIaVSvt9/eL17PBhD YZaXuiVaaNYydCQogl7kY174awZ33Rhun5NbXLB3Bn6YcnLxpUSI8FD7zT8GGeX9lM XPPGGtpnDo5d60sGudKP1uoe0KNAYnMddszc8AlY= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/95989] Segmentation fault compiling with static libraries and using jthread::request_stop Date: Wed, 08 Jul 2020 15:36:16 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: see_also Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jul 2020 15:36:16 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95989 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://sourceware.org/bugz | |illa/show_bug.cgi?id=3D226= 35 --- Comment #13 from Jonathan Wakely --- 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/thr= ead 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-thread= ed - // programs, because this_thread::get_id() !=3D 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() !=3D 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) threa= d. if (!__gthread_active_p()) - return thread::id(1); + return thread::id((__gthread_t)1); #endif return thread::id(__gthread_self()); }=