
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(). http://msdn2.microsoft.com/en-us/library/ms682411(VS.85).aspx
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 course. 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? Colin