cvs commit: src/sys/kern kern_descrip.c
John Baldwin
jhb at FreeBSD.org
Fri Jan 16 14:33:17 PST 2004
On Friday 16 January 2004 04:57 pm, Dag-Erling Smørgrav wrote:
> Dag-Erling Smorgrav <des at FreeBSD.org> writes:
> > WITNESS won't let us hold two filedesc locks at the same time, so
> > juggle fdp and newfdp around a bit.
>
> The question though is, is there a real reason why we can't hold two
> filedesc locks at the same time, or is WITNESS being unnecessarily
> pedantic?
In this case you are safe because one lock doesn't even need to be held at
all. However, in the normal case this is a very valid check. It is only
safe to acquire two locks of the same type if you have a well-defined order
in the way that you lock multiple locks. For example, for proc locks, when
we do acquire them multiple times we either 1) use mtx_trylock() (which can't
block, so it's not a problem) or 2) we lock the child process first and the
parent process second. If you just arbitrarily lock two of the same type of
lock then you can get a deadlock if two different threads are trying to lock
the two same locks in reverse order. This can happen if you forget to unlock
a lock also for example. It is best to let WITNESS catch as many errors as
possible rather than just shutting them up for one special case that you
don't wish to work around. Esp. if that one case is locking something that
doesn't even need to be locked. :-)
--
John Baldwin <jhb at FreeBSD.org> <>< http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve" = http://www.FreeBSD.org
More information about the cvs-all
mailing list