From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21920 invoked by alias); 8 Mar 2005 09:49:04 -0000 Mailing-List: contact pthreads-win32-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sources.redhat.com Received: (qmail 21866 invoked from network); 8 Mar 2005 09:49:00 -0000 Received: from unknown (HELO mtagate2.de.ibm.com) (195.212.29.151) by sourceware.org with SMTP; 8 Mar 2005 09:49:00 -0000 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate2.de.ibm.com (8.12.10/8.12.10) with ESMTP id j289mx96121532 for ; Tue, 8 Mar 2005 09:48:59 GMT Received: from d12av04.megacenter.de.ibm.com (d12av04.megacenter.de.ibm.com [9.149.165.229]) by d12nrmr1607.megacenter.de.ibm.com (8.12.10/NCO/VER6.6) with ESMTP id j289mxTB168706 for ; Tue, 8 Mar 2005 10:48:59 +0100 Received: from d12av04.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av04.megacenter.de.ibm.com (8.12.11/8.12.11) with ESMTP id j289mwbW002262 for ; Tue, 8 Mar 2005 10:48:58 +0100 Received: from d12ml062.megacenter.de.ibm.com (d12ml062.megacenter.de.ibm.com [9.149.166.219]) by d12av04.megacenter.de.ibm.com (8.12.11/8.12.11) with ESMTP id j289mv7W002248; Tue, 8 Mar 2005 10:48:57 +0100 In-Reply-To: <1110262256.6900.118.camel@desk.home> Subject: Re: starvation in pthread_once? To: Ross Johnson Cc: Pthreads-Win32 list Message-ID: From: Alexander Terekhov Date: Tue, 08 Mar 2005 09:49:00 -0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII X-SW-Source: 2005/txt/msg00032.txt.bz2 [... pthread_once() and cancelation ...] > Should one or more waiting threads get woken up and made to > re-compete to run the init routine? Yes. As for the rest, what you need here is DCSI-TLS or DCSI-MBR (acquire/release memory barriers are needed on both Itanic and XBOX NEXT... and, apart from hardware memory model, compiler shall respect acquire/release semantics on IA-32 as well). For serialization simply use a named mutex associated with address of control variable and process id (to minimize contention). DCSI-TLS: (__declspec(thread) for control variable; DLL issues aside for a moment) if (!once_control) { named_mutex::guard guard(&once_control); if (!once_control) { once_control = true; } } DCSI-MBR: (atomic<> for control variable) if (!once_control.load(msync::acq)) { named_mutex::guard guard(&once_control); if (!once_control.load(msync::none)) { once_control.store(true, msync::rel); } } regards, alexander.