Re: recursive mutexes

From: David Hopwood (david.nospam.hopwood_at_blueyonder.co.uk)
Date: 05/19/05


Date: Thu, 19 May 2005 00:31:37 GMT

David Schwartz wrote:
> red floyd wrote:
>
>>May I ask why?
>
> There are two possibilities:
>
> 1) You don't know the mutex is being used recursively. In this case, the
> recursive mutex will hide a serious problem.
>
> 2) You know the mutex is being recursively. In this case, just don't
> lock it since you know it's already locked anyway.

It is sometimes the case that you have code which can usefully be called either
with the mutex already held or with it not already held. This happens in
particular when you have an object protected by a mutex, and some method of
that object can potentially take the same object as an argument.

It's not a very common case, admittedly.

-- 
David Hopwood <david.nospam.hopwood@blueyonder.co.uk>