From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24557 invoked by alias); 8 May 2013 17:51:38 -0000 Mailing-List: contact libc-ports-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: libc-ports-owner@sourceware.org Received: (qmail 24502 invoked by uid 89); 8 May 2013 17:51:37 -0000 X-Spam-SWARE-Status: No, score=0.1 required=5.0 tests=AWL,BAYES_00,KHOP_DYNAMIC2,RDNS_DYNAMIC,TVD_RCVD_IP autolearn=no version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from 216-12-86-13.cv.mvl.ntelos.net (HELO brightrain.aerifal.cx) (216.12.86.13) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 08 May 2013 17:51:37 +0000 Received: from dalias by brightrain.aerifal.cx with local (Exim 3.15 #2) id 1Ua8Wa-00070F-00; Wed, 08 May 2013 17:51:32 +0000 Date: Wed, 08 May 2013 17:51:00 -0000 To: Torvald Riegel Cc: GLIBC Devel , libc-ports Subject: Re: [PATCH] Unify pthread_once (bug 15215) Message-ID: <20130508175132.GB20323@brightrain.aerifal.cx> References: <1368024237.7774.794.camel@triegel.csb> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1368024237.7774.794.camel@triegel.csb> User-Agent: Mutt/1.5.21 (2010-09-15) From: Rich Felker X-SW-Source: 2013-05/txt/msg00038.txt.bz2 On Wed, May 08, 2013 at 04:43:57PM +0200, Torvald Riegel wrote: > Note that this will make a call to pthread_once that doesn't need to > actually run the init routine slightly slower due to the additional > acquire barrier. If you're really concerned about this overhead, speak > up. There are ways to avoid it, but it comes with additional complexity > and bookkeeping. On the one hand, I think it should be avoided if at all possible. pthread_once is the correct, canonical way to do initialization (as opposed to hacks like library init functions or global ctors), and the main doubt lots of people have about doing it the correct way is that they're going to kill performance if they call pthread_once from every point where initialization needs to have been completed. If every call imposes memory synchronization, performance might become a real issue discouraging people from following best practices for library initialization. On the other hand, I don't think it's conforming to elide the barrier. POSIX states (XSH 4.11 Memory Synchronization): "The pthread_once() function shall synchronize memory for the first call in each thread for a given pthread_once_t object." Since it's impossible to track whether a call is the first call in a given thread, this means every call to pthread_once() is required to be a full memory barrier. I suspect this is unintended, and we should perhaps file a bug report with the Austin Group and see if the requirement can be relaxed. Rich