From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dmta1010.nifty.com (mta-snd01014.nifty.com [106.153.227.46]) by sourceware.org (Postfix) with ESMTPS id 84D8E3858C50 for ; Mon, 22 Jan 2024 03:30:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 84D8E3858C50 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 84D8E3858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=106.153.227.46 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705894231; cv=none; b=wiY6Cqd/7rzYp2+IP2gej9SVrraN2tsxnkYD6VvDJQFP0DLzD3C4rKXsGysUFbA/C9q8QobHxP4rlFOrUhTeXhldocTn1EorppOpkMrxVhbnuEUlnkMkJaiEg+PHZsgxTa9L2cjHMuDVzd4xMmJ/H88tC2JJFud8MoapO05A7AA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705894231; c=relaxed/simple; bh=MEbo0FWSSzicFbtCBPRGFS6JfArfQpZt2cBydI2/u28=; h=Date:From:To:Subject:Message-Id:Mime-Version; b=pEbiwPEykBzRyiXSGEkdD+kdxmDUiCL0LpnQoV+B6e3L5IGxsPQyYB/TatFm3/7kEApow+p6GASOXGogDqVPnKpMxJ8v+7+EFa/RDkFo4iw7lljkQACuwNRBhIiLiGGqqgWZinGt0dKb67MA+vydTstk5gcNSrVhl/FXTUUm2WA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from HP-Z230 by dmta1010.nifty.com with ESMTP id <20240122033023902.WHZL.8684.HP-Z230@nifty.com> for ; Mon, 22 Jan 2024 12:30:23 +0900 Date: Mon, 22 Jan 2024 12:30:23 +0900 From: Takashi Yano To: cygwin@cygwin.com Subject: Re: Possiblly bug of cygwin1.dll Message-Id: <20240122123023.b8eaac0e50d1e8856f44a115@nifty.ne.jp> In-Reply-To: <87fryqizl3.fsf@> 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@> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.2 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 Sun, 21 Jan 2024 14:30:00 +0100 ASSI wrote: > Takashi Yano via Cygwin writes: > > I found the cause. In pthread.h of cygwin, PTHREAD_ONCE_INIT is defined as: > > #define PTHREAD_ONCE_INIT { PTHREAD_MUTEX_INITIALIZER, 0 } > > however, libstdc++ initializes non-static pthread_once_t using this macro. > > https://www.ibm.com/docs/en/aix/7.3?topic=p-pthread-once-init-macro > https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_once.html > > "The behavior of pthread_once() is undefined if once_control has > automatic storage duration or is not initialized by PTHREAD_ONCE_INIT." > > > I cannot find the POSIX statement that only static pthread_once_t can be > > initialized using PTHREAD_ONCE_INIT. If I do not overlook something, > > this is the problem of cygwin side, isn't it? > > You can initialize just about anything with PTHREAD_ONCE_INIT, but you > cannot expect the resulting structure to work as intended if there is > more than instance per library / program, so the libstdc++ object should > be a singleton, not automatic. > > Still looks like ATWIL to me… Thanks for the information. Anyway, I confirmed the two patches (one is for gcc, the other is for cygwin) resolve the issue. PATCH1: (for gcc) Do not use PTHREAD_MUTEX_INITIALIZER etc. for non-static pthread_mutex_t. diff -ur origsrc/gcc-13-20230902/libgcc/gthr-posix.h src/gcc-13-20230902/libgcc/gthr-posix.h --- origsrc/gcc-13-20230902/libgcc/gthr-posix.h 2023-09-03 07:32:49.000000000 +0900 +++ src/gcc-13-20230902/libgcc/gthr-posix.h 2024-01-22 09:04:54.342189600 +0900 @@ -34,6 +34,12 @@ #include +#ifdef __CYGWIN__ +#define _GTHREAD_USE_MUTEX_INIT_FUNC 1 +#define _GTHREAD_USE_RECURSIVE_MUTEX_INIT_FUNC 1 +#define _GTHREAD_USE_COND_INIT_FUNC 1 +#endif + #if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \ || !defined(_GTHREAD_USE_MUTEX_TIMEDLOCK)) # include 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); -- Takashi Yano