This is a small part of my code:
CRITICAL_SECTION _cs;
InitializeCriticalSection(&_cs);
void lock() {
if (_initizalized){
EnterCriticalSection(&_cs);
EnterCriticalSection(&_cs);
_locked = true;
}
}
(I wrote “EnterCriticalSection” twice , because I noticed that this line doesn’t work)
As I understand, this must cause a deadlock. but it doesn’t. why?
No the same thread can enter it as often as it wants.
CRITICAL_SECTION is used to restrict access between multiple different threads.