DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 44TB5OZs1623282 Authentication-Results: delorie.com; dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=Gdl9qjDg X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E87C3858288 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1716980722; bh=hFAKoJFrfTMkuQSHQIayIxoGmpWA9Y8GveDwmR5KLHc=; h=Date:To:Cc:Subject:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Gdl9qjDgln4SGrlh0m3QnKR6eC+1j9YEQ+cVtM9aPeGnAEgBjVT/gfM5ckGKBhter 2pCnTezU5wXAlRlgkc9eODho4kFhaZObkxVy2xoQCK4i96VqrB4dItf9xxy93c3su/ cz7Ub9inyjd/ueNslhO4qNe5/8MpHWRN23Ha5nao= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 71854385E827 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 71854385E827 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716980696; cv=none; b=p8mRzWvN8hj7CJIG+DseDA3JARIZhV2DTTq22SBN7B0ZtMv0KFrrQIppiSr/o8TS8ciriWnNauy0eBRbdA7mnLpJMg/hCb6neG/NNXZRCpee0tSYP+HCVVFqV8d+u+hpDDaoDBBpAoyPTIRZ/RwdPqj+f60EEGhkXOMLmxgsdBM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716980696; c=relaxed/simple; bh=7uKy7KsXTRIZKlHA76FFVZmEPSdbw9lVEQ63ILLsXsI=; h=Date:From:To:Subject:Message-Id:Mime-Version:DKIM-Signature; b=qBXWbZ3o/pqEg6kIIoAD9Qt3R3Usw6HZbCW4C5eATV28DpQnkvJEDKVYLykrxsNXSHEZAvcczAb/XuQU0xFcyRFXuGbc/dtaoB81Vlq7YCMTUAZHUH58vYkqMlccOCKQPDBl/2OdF+Qwvn/oEBZT7gCgdiSkssUV8USMPxu+8Wo= ARC-Authentication-Results: i=1; server2.sourceware.org Date: Wed, 29 May 2024 20:04:48 +0900 To: Bruno Haible Cc: cygwin AT cygwin DOT com Subject: Re: multithreading broken in Cygwin 3.5.3 Message-Id: <20240529200448.fde3a5904e9b17cbdf12f20d@nifty.ne.jp> In-Reply-To: <4580924.dSzdyWo4uF@nimes> References: <3631253 DOT RrQHTzY0li AT nimes> <20240529190619 DOT 53c5820ecafcf31909c4320c AT nifty DOT ne DOT jp> <4580924 DOT dSzdyWo4uF AT nimes> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_NUMSUBJECT, 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 X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.30 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Takashi Yano via Cygwin Reply-To: Takashi Yano Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" On Wed, 29 May 2024 12:26:31 +0200 Bruno Haible wrote: > Takashi Yano wrote: > > As you mentioned in private mail to me, this seems to be a regression of > > pthread::once() introduced by > > commit 2c5433e5da8216aaf7458e50c63683c68fb0d3e8. > > > > I'll submit a patch for that issue shortly. > > My workaround implementation of pthread_once (in gnulib) looks like this: > > /* This would be the code, for > typedef struct > { > pthread_mutex_t mutex; > _Atomic unsigned int num_threads; > _Atomic unsigned int done; > } > pthread_once_t; > */ > if (once_control->done == 0) > { > once_control->num_threads += 1; > pthread_mutex_lock (&once_control->mutex); > if (once_control->done == 0) > { > (*initfunction) (); > once_control->done = 1; > } > pthread_mutex_unlock (&once_control->mutex); > if ((once_control->num_threads -= 1) == 0) > pthread_mutex_destroy (&once_control->mutex); > } > > It makes sure that > - The last thread that had been dealing with the mutex deletes > the mutex. > - Once the mutex is deleted, is it never again accessed. The > entry test of the 'done' boolean ensures this. Thanks for the advice. The problem is that we cannot change the type of pthread_once_t for binary compatibility. My patch stops to use pthread_mutex_t mutex in pthread_once_t however it cannot be deleted despite it is not used at all. -- Takashi Yano -- 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