Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Dec 2011 17:59:13 +0100
From:      =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no>
To:        John Baldwin <jhb@freebsd.org>
Cc:        Poul-Henning Kamp <phk@phk.freebsd.dk>, freebsd-threads@freebsd.org, freebsd-arch@freebsd.org
Subject:   Re: [Patch] C1X threading support
Message-ID:  <86zkeksftq.fsf@ds4.des.no>
In-Reply-To: <201112211028.26780.jhb@freebsd.org> (John Baldwin's message of "Wed, 21 Dec 2011 10:28:26 -0500")
References:  <73233.1324389741@critter.freebsd.dk> <86hb0ut1hq.fsf@ds4.des.no> <201112211028.26780.jhb@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
John Baldwin <jhb@freebsd.org> writes:
> Dag-Erling Sm=C3=B8rgrav <des@des.no> writes:
> > Poul-Henning Kamp <phk@phk.freebsd.dk> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86zkeksftq.fsf>