[Patch] C1X threading support

Dag-Erling Smørgrav des at des.no
Thu Dec 22 16:59:18 UTC 2011


John Baldwin <jhb at freebsd.org> writes:
> Dag-Erling Smørgrav <des at des.no> writes:
> > Poul-Henning Kamp <phk at phk.freebsd.dk> writes:
> > > 	mtx_unlock(l)
> > > 	{
> > > 		assert(l->id == thread_id);
> > > 		l->id = 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 != 0);
> > > 		assert(l->id == 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
-- 
Dag-Erling Smørgrav - des at des.no


More information about the freebsd-arch mailing list