From bfb16b0edef49b8e694bcb1b419bfcb5a0a3dfac Mon Sep 17 00:00:00 2001 From: Takashi Yano Date: Fri, 23 Jun 2023 00:07:26 +0900 Subject: Cygwin: thread: Reset _my_tls.tid if it's pthread_null in init_mainthread(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. https://cygwin.com/pipermail/cygwin/2023-June/253792.html With this patch, _my_tls.tid is re-initialized in pthread:: init_mainthread() if it is pthread_null. Reported-by: Mümin A. Reviewed-by: Corinna Vinschen Signed-off-by: Takashi Yano --- winsup/cygwin/thread.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'winsup') diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index 5c1284a..f614e01 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -364,7 +364,7 @@ void pthread::init_mainthread () { pthread *thread = _my_tls.tid; - if (!thread) + if (!thread || thread == pthread_null::get_null_pthread ()) { thread = new pthread (); if (!thread) -- cgit v1.1