title: CRITICAL_SECTION / CONDITION_VARIABLE Deadlock in Win32
body: <p>Why does this code cause a deadlock?</p>
  
  <p>THREAD 1:</p>
  
  <pre><code>EnterCriticalSection( &amp;lock_ );
  
  ... Create thread 1
  
  EnterCriticalSection( &amp;lock_ );
  while (pred) {
      SleepConditionVariableCs( &amp;cond_, &amp;lock_ );
      // At this point, I would expect thread #2 to wake up, but it doesn't.
  }
  LeaveCriticalSection( &amp;lock_ );
  LeaveCriticalSEction( &amp;lock_ );
  </code></pre>
  
  <p>THREAD 2:</p>
  
  <pre><code>EnterCriticalSection( &amp;lock_ );
  
  // This never runs
  ... Do something else for a while
  
  LeaveCriticalSection( &amp;lock_ );
  </code></pre>
  
  <p>According to the Win32 API, EnterCriticalSection can be called twice in a row from the same thread without deadlocking.  It appears that SleepConditionVariableCS only unlocks the critical section once, which means that thread #2 will never run.  Is my reasoning correct here?  </p>
  
  <p>Basically, what I want is something like Java's ReentrantLock.  What's the difference between ReentrantLock and CRITICAL_SECTION?</p>