title: Qt5 QWaitCondition example
body: <p>I am getting myself familiar with QT5 concurrency library. I was looking at the QWaitCondition example (<a href="http://qt-project.org/doc/qt-5.0/qtcore/qwaitcondition.html#details">http://qt-project.org/doc/qt-5.0/qtcore/qwaitcondition.html#details</a>).<br>
  Here, one thread (Thread B), reads user input, and all other threads (Thread A) process this input.</p>
  
  <p><strong>Thread A:</strong></p>
  
  <pre><code>forever {
      mutex.lock();
      keyPressed.wait(&amp;mutex);
      ++count;
      mutex.unlock();
  
      do_something();
  
      mutex.lock();
      --count;
      mutex.unlock();
  }
  </code></pre>
  
  <p><strong>Thread B:</strong></p>
  
  <pre><code>forever {
      getchar();
  
      mutex.lock();
      // Sleep until there are no busy worker threads
      while (count &gt; 0) {
          mutex.unlock();
          sleep(1);
          mutex.lock();
      }
      keyPressed.wakeAll();
      mutex.unlock();
  }
  </code></pre>
  
  <p>The reason for using count variable and the extensive mutex synchronization is to prevent symbols loss.<br>
  The problem is, I think there is still a chance that a symbol will get lost:
  imagine the following scenario:</p>
  
  <ol>
  <li><p>Thread A processes a symbol, and decreases the countes (--count);
  the mutex is released; then Thread A stops</p></li>
  <li><p>Thread B returns from sleep, aquires the mutex, sees, that count ==
      0, and calls keyPressed.wakeAll(), and then unlocks the mutex.
      However, the wakeAll() call goes to nowhere, since the Thread A is
      not waiting.</p></li>
  <li>Thread A starts again, aquaires the mutex and goes into wait().
          Since wakeAll() was already called, the symbol is lost.</li>
  </ol>
  
  <p>Am I right, or am I missing something? If I am right, how to correct the example to really prevent it from skipping the symbols?</p>