[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Bug in mutex_owned() ?
On Sunday 25 October 2009 17:58:55 Mindaugas Rasiukevicius wrote:
> Hans Petter Selasky <hselasky%c2i.net@localhost> wrote:
> > > Yes, it is a comparison. Which is correct for the purpose.
> > And what is the purpose of that function? Internal only?
> It is described in mutex(9). Purpose is NOT to make locking decisions, but
> for diagnostic checks only. If some code requires that - it most likely
> has design problems.
> > The comparison is right when done by the locking CPU, but if there are
> > two CPU's and the non-locking CPU checks this flag at the same time, it
> > gets a 1 aswell, which is wrong.
> True, except it is not wrong. Purpose of mutex_owned() is to verify that
> current LWP holds the lock, for which it is enough to test that spin-lock
> is generally held.
Ok, I get it. I confused it with mtx_owned() on FreeBSD which I am more used
> It can test that current CPU holds the lock, but it wont buy you anything,
> because if your context (thus CPU) is not holding the lock, then such test
> is useless - lock state is free to change (e.g. other CPUs can release or
> acquire your lock at the same time).
The test is in-fact useful for more than assertions. Like when implementing
statements to avoid recursive locking. I disagree that it is purely bad design
that leads one to require mutex_owned() checks.
Main Index |
Thread Index |