X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3ADE03858C5E
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1705923835;
	bh=h/9XRSME3SY1Jj8d25pyhgOJIIUk7Xa3cGqFnpyg7ns=;
	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=RwWctRogsPE7lU5ZU/mwQEjchi41P8oATALJVT6CaTPNho0l4jAgau9qTAzLnjvkU
	 M5yBwuMnHjLTFX2VkG5ji9gcvQhVXOEiQ9zZAVoqW2j0x/tWPz/g0PXexgWFh9vrOd
	 sZrkRDqHeeSjAfXbGtQhUAwwZiNKO0MRnFgtahkA=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61839385841A
Date: Mon, 22 Jan 2024 12:42:56 +0100
To: cygwin@cygwin.com
Subject: Re: Possiblly bug of cygwin1.dll
Message-ID: <Za5UwGAsOIQ-CZ2N@calimero.vinschen.de>
Mail-Followup-To: cygwin@cygwin.com
References: <ZaqHGElhXZIc3NFX@calimero.vinschen.de>
 <20240120131825.4157c259fe058155137d6fe0@nifty.ne.jp>
 <20240120141349.cde31e62177a0405b0ee9934@nifty.ne.jp>
 <87v87ov03x.fsf@Gerda.invalid>
 <20240120212427.1e69fd3655ece73ecd508def@nifty.ne.jp>
 <20240121201051.795a4405576a97ab8729e273@nifty.ne.jp>
 <87fryqizl3.fsf@>
 <20240122123023.b8eaac0e50d1e8856f44a115@nifty.ne.jp>
 <Za40iEPcedfBSt5n@calimero.vinschen.de>
 <20240122200634.bcb3408c9d4722b9a914afcf@nifty.ne.jp>
MIME-Version: 1.0
Content-Disposition: inline
In-Reply-To: <20240122200634.bcb3408c9d4722b9a914afcf@nifty.ne.jp>
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.30
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Corinna Vinschen via Cygwin <cygwin@cygwin.com>
Reply-To: cygwin@cygwin.com
Cc: Corinna Vinschen <corinna-cygwin@cygwin.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces+archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>

On Jan 22 20:06, Takashi Yano via Cygwin wrote:
> On Mon, 22 Jan 2024 10:25:28 +0100
> Corinna Vinschen wrote:
> > On Jan 22 12:30, Takashi Yano via Cygwin wrote:
> > > PATCH2: (for cygwin)
> > > Avoid handle leak caused when non-static pthread_once_t is initialized
> > > with PTHREAD_ONCE_INIT
> > > diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
> > > index 7bb4f9fc8..127569160 100644
> > > --- a/winsup/cygwin/thread.cc
> > > +++ b/winsup/cygwin/thread.cc
> > > @@ -2060,6 +2060,9 @@ pthread::once (pthread_once_t *once_control, void (*init_routine) (void))
> > >      {
> > >        init_routine ();
> > >        once_control->state = 1;
> > > +      pthread_mutex_unlock (&once_control->mutex);
> > > +      while (pthread_mutex_destroy (&once_control->mutex) == EBUSY);
> > > +      return 0;
> > >      }
> > >    /* Here we must remove our cancellation handler */
> > >    pthread_mutex_unlock (&once_control->mutex);
> > 
> > I see what you're doing here.  Wouldn't it be simpler, though, to do this?
> > 
> > diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
> > index 7bb4f9fc8341..7ec3aace395d 100644
> > --- a/winsup/cygwin/thread.cc
> > +++ b/winsup/cygwin/thread.cc
> > @@ -2063,6 +2063,7 @@ pthread::once (pthread_once_t *once_control, void (*init_routine) (void))
> >      }
> >    /* Here we must remove our cancellation handler */
> >    pthread_mutex_unlock (&once_control->mutex);
> > +  while (pthread_mutex_destroy (&once_control->mutex) == EBUSY);
> >    return 0;
> >  }
> 
> In this code, if several threads call pthread_once() at the same time,
> only one thread will succeed pthread_mutex_destroy() and the others
> will fail with EINVAL. But it does not matter. The code will be
> simpler.

Yeah, but you're right.  It's cleaner to do this only in the thread
actually performing the init action so your original patch makes
more sense.


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
