Answered what happens if EnterCriticalSection times out?

  • Wednesday, February 01, 2012 6:14 AM
     
      Has Code

    Hi,

    What happens if EnterCriticalSection() raises EXCEPTION_POSSIBLE_DEADLOCK if a wait operation on the critical section times out. To be specific, the code between EnterCriticalSection() and LeaveCriticalSection() is executed or not?

    For Example

    DWORD WINAPI ThreadProc( LPVOID lpParameter )
    {
        ...
    
        // Request ownership of the critical section.
        EnterCriticalSection(&CriticalSection); 
    
        // Access the shared resource.
    
        // Release ownership of the critical section.
        LeaveCriticalSection(&CriticalSection);
    
        ...
    return 1;
    }
    

     In this example, will the code to be executed in critical section be executed, if EnterCriticalSection times out.

     

    Dhanyawaad (Thanks)

All Replies

  • Wednesday, February 01, 2012 3:12 PM
     
     Answered

    Should that occur, it will be thrown as an SEH exception.  In your example above, nothing else in ThreadProc will be executed at that point.  The process will likely be torn down as the exception is unhandled.

    • Marked As Answer by Optimus22 Monday, February 13, 2012 5:29 AM
    •  
  • Monday, February 13, 2012 5:29 AM
     
     

    Thanks Bill, 

    This was helpful.

    Dhanyawaad (Thanks)