From owner-freebsd-arch@FreeBSD.ORG Mon Dec 17 02:19:22 2007 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3F8A216A421; Mon, 17 Dec 2007 02:19:22 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (bsdimp.com [199.45.160.85]) by mx1.freebsd.org (Postfix) with ESMTP id F2CE313C458; Mon, 17 Dec 2007 02:19:21 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from localhost (localhost [127.0.0.1]) by harmony.bsdimp.com (8.14.1/8.14.1) with ESMTP id lBH2Ekmu062691; Sun, 16 Dec 2007 19:14:46 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Sun, 16 Dec 2007 19:16:41 -0700 (MST) Message-Id: <20071216.191641.-1402074010.imp@bsdimp.com> To: jan.grant@bristol.ac.uk From: "M. Warner Losh" In-Reply-To: <20071204085502.N83722@tribble.ilrt.bris.ac.uk> References: <20071203235929.685d3674@Karsten.Behrmanns.Kasten> <20071204014614.GE76623@elvis.mu.org> <20071204085502.N83722@tribble.ilrt.bris.ac.uk> X-Mailer: Mew version 5.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: BearPerson@gmx.net, alfred@freebsd.org, freebsd-arch@freebsd.org Subject: Re: Code review request: small optimization to localtime.c X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Dec 2007 02:19:22 -0000 In message: <20071204085502.N83722@tribble.ilrt.bris.ac.uk> Jan Grant writes: : On Mon, 3 Dec 2007, Alfred Perlstein wrote: : : [on the double-checked locking idiom] : : > Karsten, _typically_ (but not always) an "unlock" operation : > requires that writes prior to the unlock be globally visible. : > : > This is why it works almost everywhere. : : Perhaps, but if you use it you should probably mark the code with : /* XXX not guaranteed to be correct by POSIX */ : : Double-checked locking is broken without an appropriate barrier. : "Correctness over speed" should surely be our watchword :-) Actually, the code I posted for review *IS* posixly correct. It doesn't matter if the write posts or not. If it doesn't post, then we know the guard variable will be false still and we take out the lock, test it see that it is true (since nothing would work well if the lock/unlock pairs didn't force a consistent variable after the lock is released). If it is posted, we don't take the branch. Since these variables are initialized to zero and set exactly once to true, the above is true. pthread_once() is more optimal, but a larger code change. Warner