From owner-freebsd-threads@FreeBSD.ORG Tue Apr 24 18:13:09 2012 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BC7D61065673; Tue, 24 Apr 2012 18:13:09 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 18FF98FC0A; Tue, 24 Apr 2012 18:13:08 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q3OID3Rq081651; Tue, 24 Apr 2012 21:13:03 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q3OID2Xc039889; Tue, 24 Apr 2012 21:13:02 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q3OID2Fn039888; Tue, 24 Apr 2012 21:13:02 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 24 Apr 2012 21:13:02 +0300 From: Konstantin Belousov To: Martin Simmons Message-ID: <20120424181302.GB2358@deviant.kiev.zoral.com.ua> 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> <201204241800.q3OI0X89007384@higson.cam.lispworks.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="6lA9ewhm9nShhcj2" Content-Disposition: inline In-Reply-To: <201204241800.q3OI0X89007384@higson.cam.lispworks.com> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.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:13:09 -0000 --6lA9ewhm9nShhcj2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Apr 24, 2012 at 07:00:33PM +0100, Martin Simmons wrote: > >>>>> On Tue, 24 Apr 2012 19:58:42 +0300, Konstantin Belousov said: > >=20 > > + > > + /* > > + * Lock the spinlock used to protect __sglue list walk in > > + * __sfp(). The __sfp() uses fp->_flags =3D=3D 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 =3D 0; /* Release this FILE for reuse. */ > > + STDIO_THREAD_UNLOCK(); > > FUNLOCKFILE(fp); > > return (r); >=20 > Is that assumption about reordering correct? I.e. is FreeBSD's spinlock a > two-way barrier? >=20 > 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). Taking the lock prevents the __sfp from iterating the list until the spinlock is released. Since release makes sure that all previous memory operations become visible, the acquire in the spinlock lock provides the neccesary guarentee. --6lA9ewhm9nShhcj2 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAk+W7S4ACgkQC3+MBN1Mb4j2XwCfUwYZ5frhFeuNuQblrpS/xCMH lKAAoMVOuTnHmMBWsL/5YaWIBx+Me3xq =YN7b -----END PGP SIGNATURE----- --6lA9ewhm9nShhcj2--