diff --git a/Thread.cpp b/Thread.cpp index 06ba691a..44f7174c 100644 --- a/Thread.cpp +++ b/Thread.cpp @@ -63,6 +63,14 @@ void Mutex::Lock() { #ifdef WIN32 EnterCriticalSection(&m_mutexObj); +#ifdef DEBUG + // CriticalSections on Windows can be locked many times from the same thread, + // but we do not want this and must treat such situations as errors and detect them. + if (m_mutexObj.RecursionCount > 1) + { + error("Internal program error: inconsistent thread-lock detected"); + } +#endif #else pthread_mutex_lock(&m_mutexObj); #endif