public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Takashi Yano <tyan0@sourceware.org>
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().
Date: Mon,  3 Jul 2023 11:04:01 +0000 (GMT)	[thread overview]
Message-ID: <20230703110401.2C82A3858C54@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=fcaa1c496768f0781fe7515852ff7dc3bda67e78

commit fcaa1c496768f0781fe7515852ff7dc3bda67e78
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Fri Jun 23 00:07:26 2023 +0900

    Cygwin: thread: Reset _my_tls.tid if it's pthread_null in init_mainthread().
    
    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. <muminaydin06@gmail.com>
    Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
    Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>

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 = _my_tls.tid;
-  if (!thread)
+  if (!thread || thread == pthread_null::get_null_pthread ())
     {
       thread = new pthread ();
       if (!thread)

                 reply	other threads:[~2023-07-03 11:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230703110401.2C82A3858C54@sourceware.org \
    --to=tyan0@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).