Windows Mutex seems to be able to get the acquired lock again (recursively) if the thread that owns the lock tries to get it.
But posix-based pthread locks do not allow this behavior.
Is there any compile-time macro or any settings that could cause mutex windows to behave just like mutex pthread?
While you're programming on Windows, avoid overriding the behavior of its Mutex. This re-entry of the same stream is absolutely necessary for its specific behavior.
- , 1. CreateSemaphore().
Fwiw, , . , . , concurrency. .
, Windows . Posix , pthread_mutexattr_settype() PTHREAD_MUTEX_RECURSIVE, .
pthread_mutexattr_settype()
PTHREAD_MUTEX_RECURSIVE
Windows . , , , . nobugz, , 1, .
, ( , ). 1, .
I suggest using read / write locks (aka SRW) . Like Windows Mutex, they are not recursive. As critical sections, they are lightweight and do not name the kernel if they are free ( Benchmarks ).
Take a look at this article in the 'fast mutex' section .
These types of mutexes cannot be recursively derived.
Of course, you will need to learn how to implement them in C.