Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Mar 2016 15:12:20 -0700
From:      John Baldwin <jhb@freebsd.org>
To:        Bryan Drewery <bdrewery@freebsd.org>
Cc:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r296947 - head/share/man/man9
Message-ID:  <1525892.cfDzejblxM@ralph.baldwin.cx>
In-Reply-To: <201603161839.u2GIdm5C072960@repo.freebsd.org>
References:  <201603161839.u2GIdm5C072960@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wednesday, March 16, 2016 06:39:48 PM Bryan Drewery wrote:
> Author: bdrewery
> Date: Wed Mar 16 18:39:48 2016
> New Revision: 296947
> URL: https://svnweb.freebsd.org/changeset/base/296947
> 
> Log:
>   Remove incorrect BUGS entry about asserting lock not held.
>   
>   For non-WITNESS< assertion support for SA_UNLOCKED was added in r125421 and
>   made to panic in r126316.
>   
>   MFC after:	1 week

Eh, how can this possibly work?

That is, suppose I have this code:

	sx_slock(&foo);
	sx_assert(&foo, SA_UNLOCKED);

How does that safely work without WITNESS?  It needs to not panic in the case
that some other thread does sx_slock(&foo).  In fact, the comment (modulo the
spelling nit) says this explicitly:

        case SA_UNLOCKED:
#ifdef WITNESS
                witness_assert(&sx->lock_object, what, file, line);
#else
                /*
                 * If we hold an exclusve lock fail.  We can't
                 * reliably check to see if we hold a shared lock or
                 * not.
                 */
                if (sx_xholder(sx) == curthread)
                        panic("Lock %s exclusively locked @ %s:%d\n",
                            sx->lock_object.lo_name, file, line);
#endif
                break;

You could perhaps reword the bug to say that SA_UNLOCKED will panic if the lock
is exclusively locked in the non-WITNESS case, but will fail to panic if the
thread holds a shared lock.

The wording in rwlock(9) is better than sx(9) though it should mention that
RA_UNLOCKED can detect a write lock.  That wording could then be used in sx(9).

-- 
John Baldwin



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