Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a Windows CRITICAL_SECTION object be configured to deny recursive access?

By default, a CRITICAL_SECTION object is recursive. Can this behaviour be configured like a pthread mutex to enable or disable recursive thread access?

To clarify in response to the comments: I am referring specifically to a Windows CRITICAL_SECTION object, not a Windows mutex.

like image 762
x-x Avatar asked Oct 29 '12 07:10

x-x


2 Answers

No, it cannot. Documented APIs do not mention this in any way. Windows critical sections always accept recursive access.

like image 151
Kirill Kobelev Avatar answered Sep 20 '22 12:09

Kirill Kobelev


A Critical Section always allows recursion within a thread. So does a Mutex. That is by design and cannot be changed.

A Semaphore, on the other hand, can prevent recursion within a thread. See MSDN documentation for more details.

like image 27
Remy Lebeau Avatar answered Sep 21 '22 12:09

Remy Lebeau