Can a Windows CRITICAL_SECTION object be configure

2019-07-04 11:55发布

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.

2条回答
闹够了就滚
2楼-- · 2019-07-04 12:39

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

查看更多
你好瞎i
3楼-- · 2019-07-04 12:49

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.

查看更多
登录 后发表回答