Is it valid to nest a critical section?

前端 未结 3 1325
时光取名叫无心
时光取名叫无心 2020-12-16 13:19

For example, would this be valid?

CRITICAL_SECTION cs;

::InitializeCriticalSection( &cs );

::EnterCriticalSection( &cs );      // First level
::Ent         


        
3条回答
  •  清酒与你
    2020-12-16 13:36

    From the documentation:

    After a thread has ownership of a critical section, it can make additional calls to EnterCriticalSection or TryEnterCriticalSection without blocking its execution. This prevents a thread from deadlocking itself while waiting for a critical section that it already owns. The thread enters the critical section each time EnterCriticalSection and TryEnterCriticalSection succeed. A thread must call LeaveCriticalSection once for each time that it entered the critical section.

提交回复
热议问题