delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2023/06/22/07:50:30

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C0863858C30
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1687434587;
bh=zBE9bj1mTthAfB61/2Qd6pV/2LojmbD5RaVb5AUZGuk=;
h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:
From;
b=flCb7R6a+tDpxllZHZO9a5bYYBhCwKKiB3aF9w26MtCnorNFnYzUxzinBuxFH5u14
0QyYJ+DivA/Q6VuVTQ24MUPnOuzUnOxebkSglcRf6O/QdeS+/TtSsClQnXg+vyPMT+
AS8UKWcW76tL1NmEdpv2GmB7vkxAkBcY0nT+dM9A=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D6F0C3858C2D
Date: Thu, 22 Jun 2023 13:48:53 +0200
To: Takashi Yano <takashi DOT yano AT nifty DOT ne DOT jp>
Subject: Re: Memory Barriers at pthread using CYGWIN
Message-ID: <ZJQ1JYyz9Wu+x5XA@calimero.vinschen.de>
Mail-Followup-To: Takashi Yano <takashi DOT yano AT nifty DOT ne DOT jp>,
cygwin AT cygwin DOT com
References: <CAPxKPA6zdV5UUdwcnhk9Sw159UQfVSsMjoiC4Sx3w-ojzw9Biw AT mail DOT gmail DOT com>
<CAPxKPA48sKPqwGc-jU7UQvQhsbT0N6A9LJXCAZeaa1rjeRtuNg AT mail DOT gmail DOT com>
<96718c68-af84-45a5-9332-337ec4b2f04a AT email DOT android DOT com>
<CAPxKPA6bRfF19pXrYT04TqbxettyYf=ypgfdySysqAJyB9BfxA AT mail DOT gmail DOT com>
<64831a27 DOT 170a0220 DOT 1f805 DOT 81bfSMTPIN_ADDED_BROKEN AT mx DOT google DOT com>
<1503743851 DOT 9556 DOT 1686370084334 AT aps7mgn-06>
<20230620215300 DOT def2e786b8fdce10b6317381 AT nifty DOT ne DOT jp>
<20230622191959 DOT a8ff48a0e1f1221c6de52a87 AT nifty DOT ne DOT jp>
MIME-Version: 1.0
In-Reply-To: <20230622191959.a8ff48a0e1f1221c6de52a87@nifty.ne.jp>
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Corinna Vinschen via Cygwin <cygwin AT cygwin DOT com>
Reply-To: cygwin AT cygwin DOT com
Cc: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>, cygwin AT cygwin DOT com
Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>

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

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019