- // a potential race condition can occur here
- //
- // after a thread increments m_numWaiters, and unlocks the mutex and before
- // the semaphore.Wait() is called, if another thread can cause a signal to
- // be generated
- //
- // this race condition is handled by using a semaphore and incrementing the
- // semaphore only if m_numWaiters is greater that zero since the semaphore,
- // can 'remember' signals the race condition will not occur
-
- // wait ( if necessary ) and decrement semaphore
- wxSemaError err = m_semaphore.Wait();
+ // after unlocking the mutex other threads may Signal() us, but it is ok
+ // now as we had already incremented m_numWaiters so Signal() will post the
+ // semaphore and decrement m_numWaiters back even if it is called before we
+ // start to Wait()
+ const wxSemaError err = m_semaphore.Wait();
+