From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dmta1006.nifty.com (mta-snd01007.nifty.com [106.153.227.39]) by sourceware.org (Postfix) with ESMTPS id 2B78E3858D20 for ; Mon, 22 Jan 2024 11:06:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2B78E3858D20 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=nifty.ne.jp Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=nifty.ne.jp ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2B78E3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=106.153.227.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705921602; cv=none; b=OoLq/aN78JQYkF8dUYXez0MHO8m7rVG9XzADGj+xmEkE82o5Ybb/Jsig/dynIM83xULvK8bsN4Fd195vzDOT8p0Eo6EtOgPwyw8TyV89bFEN0XCG4PHSqlnqzZAuP60biwdGGP1dgT6SwEoxncgLbcdLntiZCeiYhDHcet9klb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705921602; c=relaxed/simple; bh=9KiCAvm2JYti95+zKYwUwQJ18Fc+k6Xv3/SvgM+tqhk=; h=Date:From:To:Subject:Message-Id:Mime-Version; b=FBT83AotMpgXagxZCFuJugDXnbREHLLsmiunjACyKnjrp85jtt3Fsvg1W6SDANSpCq+7R9tXg3VXFtStsYi1zdRrP1leXYgtlBgPo+wJWKM1ngjdpO7RipE5rlzg+grpn71VEfn8U1T4xblVcDG+9PtHUyLj3bOrrMXXddLGtbM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from HP-Z230 by dmta1006.nifty.com with ESMTP id <20240122110635927.YNKQ.58378.HP-Z230@nifty.com> for ; Mon, 22 Jan 2024 20:06:35 +0900 Date: Mon, 22 Jan 2024 20:06:34 +0900 From: Takashi Yano To: cygwin@cygwin.com Subject: Re: Possiblly bug of cygwin1.dll Message-Id: <20240122200634.bcb3408c9d4722b9a914afcf@nifty.ne.jp> In-Reply-To: References: <20240119224436.876a055f356f7c6796bc725b@nifty.ne.jp> <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> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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. -- Takashi Yano