tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Bug in mutex_owned() ?
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.
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).
--
Mindaugas
Home |
Main Index |
Thread Index |
Old Index