From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 2C82A3858C54; Mon, 3 Jul 2023 11:04:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C82A3858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1688382241; bh=ncudRGLdUq9J2xVWLWNE/pwyHsgowzHkbmeQsJISpA8=; h=From:To:Subject:Date:From; b=k0dHZeo+ZLl7IrSLRrD/NUiwMkl3eTNPq/mZxBBkqI7QyKycm8l7YTEcg8TzFmhxY zTrJRre5ehU9d9YSxydjmh2GQkfk0mOO/QkhNoogTHUeQxQaHlaNI12cWukGLMMVyY /WRBeVlRw3bSZ+ZfQrwVgRxjD8uq9yO97INqQdSE= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_4-branch] Cygwin: thread: Reset _my_tls.tid if it's pthread_null in init_mainthread(). X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/cygwin-3_4-branch X-Git-Oldrev: 8c2867eebfa223d761f6f266a6c18b778ed56261 X-Git-Newrev: fcaa1c496768f0781fe7515852ff7dc3bda67e78 Message-Id: <20230703110401.2C82A3858C54@sourceware.org> Date: Mon, 3 Jul 2023 11:04:01 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Dfcaa1c49676= 8f0781fe7515852ff7dc3bda67e78 commit fcaa1c496768f0781fe7515852ff7dc3bda67e78 Author: Takashi Yano Date: Fri Jun 23 00:07:26 2023 +0900 Cygwin: thread: Reset _my_tls.tid if it's pthread_null in init_mainthre= ad(). =20 Currently, _my_tls.tid is set to pthread_null if pthread::self() is called before pthread::init_mainthread(). As a result, pthread:: init_mainthread() does not set _my_tls.tid appropriately. Due to this, pthread_join() fails in LDAP environment if the program is the first program which loads cygwin1.dll. =20 https://cygwin.com/pipermail/cygwin/2023-June/253792.html =20 With this patch, _my_tls.tid is re-initialized in pthread:: init_mainthread() if it is pthread_null. =20 Reported-by: M=C3=BCmin A. Reviewed-by: Corinna Vinschen Signed-off-by: Takashi Yano Diff: --- winsup/cygwin/thread.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index 5c1284a93..f614e01c4 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -364,7 +364,7 @@ void pthread::init_mainthread () { pthread *thread =3D _my_tls.tid; - if (!thread) + if (!thread || thread =3D=3D pthread_null::get_null_pthread ()) { thread =3D new pthread (); if (!thread)