Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 02 May 2007 19:11:21 +0200
From:      Attilio Rao <attilio@FreeBSD.org>
To:        babkin@users.sf.net
Cc:        freebsd-hackers@freebsd.org, Julian Elischer <julian@elischer.org>, Hans Petter Selasky <hselasky@c2i.net>
Subject:   Re: msleep() on recursivly locked mutexes
Message-ID:  <4638C639.7060407@FreeBSD.org>
In-Reply-To: <2782784.9021177711758431.JavaMail.root@vms073.mailsrvcs.net>
References:  <2782784.9021177711758431.JavaMail.root@vms073.mailsrvcs.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Sergey Babkin wrote:
>> From: Julian Elischer <julian@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.

If that happens rather frequently, the better thing to do is assuming 
that the lock is alredy held in the function (adding an assertion for 
it) than acquiring/releasing before/after the function.

Attilio




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