Why does this code not deadlock when entering the same critical section 2 times in a row?
Code:#define _WIN32_WINNT 0x0403 #include <Windows.h> #include <stdio.h> #include <tchar.h> CRITICAL_SECTION Mutex; int _tmain(int argc, _TCHAR* argv[]) { // Initialize the mutex if (!InitializeCriticalSectionAndSpinCount(&Mutex,0x00000001)) { wprintf(L"Could not initialize the mutex."); } EnterCriticalSection(&Mutex); EnterCriticalSection(&Mutex); wprintf(L"This should be impossible to reach because of deadlock."); LeaveCriticalSection(&Mutex); LeaveCriticalSection(&Mutex); // Release the mutex DeleteCriticalSection(&Mutex); return 0; }




Reply With Quote