From owner-freebsd-threads@FreeBSD.ORG Tue Apr 24 18:00:37 2012 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 649AD106566B; Tue, 24 Apr 2012 18:00:37 +0000 (UTC) (envelope-from martin@lispworks.com) Received: from lwfs1-cam.cam.lispworks.com (mail.lispworks.com [193.34.186.230]) by mx1.freebsd.org (Postfix) with ESMTP id E71878FC08; Tue, 24 Apr 2012 18:00:36 +0000 (UTC) Received: from higson.cam.lispworks.com (higson [192.168.1.7]) by lwfs1-cam.cam.lispworks.com (8.14.3/8.14.3) with ESMTP id q3OI0YCc028398; Tue, 24 Apr 2012 19:00:34 +0100 (BST) (envelope-from martin@lispworks.com) Received: from higson.cam.lispworks.com (localhost.localdomain [127.0.0.1]) by higson.cam.lispworks.com (8.14.4) id q3OI0X1x007388; Tue, 24 Apr 2012 19:00:33 +0100 Received: (from martin@localhost) by higson.cam.lispworks.com (8.14.4/8.14.4/Submit) id q3OI0X89007384; Tue, 24 Apr 2012 19:00:33 +0100 Date: Tue, 24 Apr 2012 19:00:33 +0100 Message-Id: <201204241800.q3OI0X89007384@higson.cam.lispworks.com> From: Martin Simmons To: Konstantin Belousov In-reply-to: <20120424165842.GZ2358@deviant.kiev.zoral.com.ua> (message from Konstantin Belousov on Tue, 24 Apr 2012 19:58:42 +0300) References: <20120423084120.GD76983@zxy.spb.ru> <201204241343.q3ODhe2C032683@higson.cam.lispworks.com> <20120424140348.GY2358@deviant.kiev.zoral.com.ua> <201204241110.14017.jhb@freebsd.org> <20120424165842.GZ2358@deviant.kiev.zoral.com.ua> Cc: jack.ren@intel.com, freebsd-threads@freebsd.org Subject: Re: About the memory barrier in BSD libc X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Apr 2012 18:00:37 -0000 >>>>> On Tue, 24 Apr 2012 19:58:42 +0300, Konstantin Belousov said: > > + > + /* > + * Lock the spinlock used to protect __sglue list walk in > + * __sfp(). The __sfp() uses fp->_flags == 0 test as an > + * indication of the unused FILE. > + * > + * Taking the lock prevents possible compiler or processor > + * reordering of the writes performed before the final _flags > + * cleanup, making sure that we are done with the FILE before > + * it is considered available. > + */ > + STDIO_THREAD_LOCK(); > fp->_flags = 0; /* Release this FILE for reuse. */ > + STDIO_THREAD_UNLOCK(); > FUNLOCKFILE(fp); > return (r); Is that assumption about reordering correct? I.e. is FreeBSD's spinlock a two-way barrier? It isn't unusual for the locking primitive to be a one-way barrier, i.e. (from Linux kernel memory-barriers.txt) "Memory operations that occur before a LOCK operation may appear to happen after it completes." See also acq and rel in atomic(9). __Martin