From owner-freebsd-arch@FreeBSD.ORG Thu Dec 22 16:59:18 2011 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 CC7931065672; Thu, 22 Dec 2011 16:59:18 +0000 (UTC) (envelope-from des@des.no) Received: from smtp.des.no (smtp.des.no [194.63.250.102]) by mx1.freebsd.org (Postfix) with ESMTP id 8D95D8FC0A; Thu, 22 Dec 2011 16:59:18 +0000 (UTC) Received: from ds4.des.no (des.no [84.49.246.2]) by smtp.des.no (Postfix) with ESMTP id 759F96D85; Thu, 22 Dec 2011 16:59:14 +0000 (UTC) Received: by ds4.des.no (Postfix, from userid 1001) id 11D3681A6; Thu, 22 Dec 2011 17:59:13 +0100 (CET) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: John Baldwin References: <73233.1324389741@critter.freebsd.dk> <86hb0ut1hq.fsf@ds4.des.no> <201112211028.26780.jhb@freebsd.org> Date: Thu, 22 Dec 2011 17:59:13 +0100 In-Reply-To: <201112211028.26780.jhb@freebsd.org> (John Baldwin's message of "Wed, 21 Dec 2011 10:28:26 -0500") Message-ID: <86zkeksftq.fsf@ds4.des.no> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: Poul-Henning Kamp , freebsd-threads@freebsd.org, Niall Douglas , freebsd-arch@freebsd.org Subject: Re: [Patch] C1X threading support 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: Thu, 22 Dec 2011 16:59:18 -0000 John Baldwin writes: > Dag-Erling Sm=C3=B8rgrav writes: > > Poul-Henning Kamp writes: > > > mtx_unlock(l) > > > { > > > assert(l->id =3D=3D thread_id); > > > l->id =3D NULL; > > > atomic_magic_unlock(l->lock_field) > > > } > > susceptible to race conditions > How so? I should have specified "if called from a thread that does not own the mutex" > > > mtx_assert_held(l) > > > { > > > assert(l->lock-field !=3D 0); > > > assert(l->id =3D=3D thread_id); > > > } > > susceptible to race conditions > How so? I was going to point out that the state of the mutex can change between the two asserts, but as you say, at least one of them is guaranteed to fail... *if* you assume that these fields can be read atomically, which was one of my objections. DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no