From: Colin Caughie (c.caughie_at_[hidden])
Date: 2008-02-08 02:50:56
Jonathan Franklin <franklin.jonathan <at> gmail.com> writes:
> As others have said, the windows critical section is recursive (and very
> lightweight). If you need non-recursive behavior, try CreateMutex().
CreateMutex also creates a recursive mutex. As far as I know there is no such
thing as a non-recursive mutex/critical section in Windows. This is kind of a
pain when writing cross-platform code.
What we do is just make sure we run all our tests on Linux as well as Windows,
on the basis that if the code works with non-recursive mutexes it'll almost
certainly work with recursive ones as well. The reverse is generally not true of
Using boost::recursive_mutex is an option that I'd recommend only if you
actually make use of the recursive behaviour.
Incidentally the Boost.Thread documentation mentions a "Checked Locking
Strategy" which would throw an exception if a thread attempts to lock a mutex
that it has already locked. But it then goes on to say that this strategy is not
implemented. Not sure if there are plans to do this in the future?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk