How to change recursive behavior of Windows Mutex lock?

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?

+5
source share
4 answers

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. .

+6

, Windows . Posix , pthread_mutexattr_settype() PTHREAD_MUTEX_RECURSIVE, .

Windows . , , , . nobugz, , 1, .

, ( , ). 1, .

+6

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 ).

+2
source

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.

0
source

All Articles