msleep() on recursivly locked mutexes

Sergey Babkin babkin at verizon.net
Fri Apr 27 22:09:35 UTC 2007


>From: Julian Elischer <julian at elischer.org>
>Basically you shouldn't have a recursed mutex FULL STOP. We have a couple 
>of instances in the kernel where we allow a mutex to recurse, but they had to be 
>hard fought, and the general rule is "Don't". If you are recursing on 
>a mutex you need to switch to some other method of doing things.
>e.g. reference counts, turnstiles, whatever.. use the mutex to create these 

One typical problem is when someone holds a mutex
and needs to call a function that also tried to get the mutex.
The typical solution for it is to provide two versions of
this function, one expecting the mutex being already held
by the caller, the other being a wrapper that grabs the mutex and
then calls the actual worker function.

-SB




More information about the freebsd-hackers mailing list