public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: Takashi Yano <takashi.yano@nifty.ne.jp>
Cc: cygwin@cygwin.com
Subject: Re: Memory Barriers at pthread using CYGWIN
Date: Thu, 22 Jun 2023 13:48:53 +0200	[thread overview]
Message-ID: <ZJQ1JYyz9Wu+x5XA@calimero.vinschen.de> (raw)
In-Reply-To: <20230622191959.a8ff48a0e1f1221c6de52a87@nifty.ne.jp>

On Jun 22 19:19, Takashi Yano via Cygwin wrote:
> Any suggestions?
> 
> On Tue, 20 Jun 2023 21:53:00 +0900
> Takashi Yano wrote:
> > I looked into this problem, and I think this is a problem regarding
> > _my_tls initialization order, so far. This seems to happen in LDAP
> > environment.
> > 
> > My assumption is:
> > 
> > If the program is the first program which load cygwin1.dll, ldap
> > connection seems to be made before pthread::init_mainthread().
> > In cyg_ldap.cc, cyg_ldap::connect(), cyg_ldap::search() or
> > cyg_ldap::next_page() calls cygwait() in which pthread::self()
> > is called.
> > 
> > Then, _my_tls.tid is initialized with null_pthread, therefore,
> > _my_tls.tid is not set in pthread::init_mainthread().
> > 
> > This causes pthread_join() failure at:
> > winsup/cygwin/thread.cc: line 2196
> >    if (!is_good_object (&joiner))
> >      return EINVAL;
> > 
> > 
> > The first idea to fix this issue is remove set_tls_self_pointer()
> > call from pthread::self().
> > 
> > diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
> > index 5c1284a93..a0f2d5546 100644
> > --- a/winsup/cygwin/thread.cc
> > +++ b/winsup/cygwin/thread.cc
> > @@ -392,10 +392,7 @@ pthread::self ()
> >  {
> >    pthread *thread = _my_tls.tid;
> >    if (!thread)
> > -    {
> > -      thread = pthread_null::get_null_pthread ();
> > -      thread->set_tls_self_pointer ();
> > -    }
> > +    thread = pthread_null::get_null_pthread ();
> >    return thread;
> >  }
> >  
> > 
> > The secnd approach is to re-initialize _my_tls.tid in
> > pthread::init_mainthread() if _my_tls.tid is null_pthread.
> > 
> > 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)
> > 
> > 
> > Which is the better approach, do you think?
> > Or any other idea?

The second approach looks good to me.  There was a reason to call
set_tls_self_pointer from pthread::self, I guess.  Resetting in
init_mainthread should have the least potential for side-effects.


Thanks,
Corinna

  reply	other threads:[~2023-06-22 11:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAPxKPA6bRfF19pXrYT04TqbxettyYf=ypgfdySysqAJyB9BfxA@mail.gmail.com>
     [not found] ` <CAPxKPA48sKPqwGc-jU7UQvQhsbT0N6A9LJXCAZeaa1rjeRtuNg@mail.gmail.com>
     [not found]   ` <96718c68-af84-45a5-9332-337ec4b2f04a@email.android.com>
2023-06-09 12:25     ` Takashi Yano
     [not found] ` <64831a27.170a0220.1f805.81bfSMTPIN_ADDED_BROKEN@mx.google.com>
2023-06-10  4:08   ` Takashi Yano
2023-06-20 12:53     ` Takashi Yano
2023-06-22 10:19       ` Takashi Yano
2023-06-22 11:48         ` Corinna Vinschen [this message]
2023-06-22 23:49           ` Takashi Yano
2023-06-08 14:29 Mümin A.
2023-06-08 14:37 ` [EXTERNAL] " Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2023-06-08 22:58   ` Mümin A.
2023-06-09  0:22     ` Takashi Yano
2023-06-09  1:44 ` Duncan Roe

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=ZJQ1JYyz9Wu+x5XA@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin@cygwin.com \
    --cc=takashi.yano@nifty.ne.jp \
    /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).