title: Qt: Does a QReadWriteLock work as shown?
body: <p>I have four threads that need to be syncronized. In order to achieve this, I am looking to pass each thread the same bool array. Each thread will change the 'corresponding' value to true once it has reached a certain point in the thread, then constantly check to see if the rest of the values are true. If so, enter the loop... An example</p>
  
  <pre><code>//above thread init stuff
  oLock-&gt;lockForWrite();
  abSync[iThreadNum] = true;  //iThreadNum = {0...3} depending on whats set
  oLock-&gt;unlock();
  
  bool bSynced = false;
  while (!bSynced)
  {
      oLock-&gt;lockForRead();
      if (abSync[0] &amp;&amp; abSync[1] &amp;&amp; abSync[2] &amp;&amp; abSync[3])
          bSynced = true;
      oLock-&gt;unlock();
  }
  
  //below thread run and finish
  </code></pre>
  
  <p>Does the QReadWriteLock work as described above? Will it in fact lock the variable for the write (as each thread goes through) but not for the read? A <a href="http://doc.qt.nokia.com/4.7/qreadwritelock.html#lockForRead" rel="nofollow noreferrer">quick look</a> at the documentation suggests that QReadWriteLock will only block at <code>lockForRead()</code> if there is a write lock but not a read lock which is what I want above.</p>
  
  <p>Also, I understand the above will suck down CPU cycles as its going through the loop and that is the wanted behavior. Using a <code>Sleep</code> is not <a href="https://stackoverflow.com/questions/85122/sleep-less-than-one-millisecond/85149#85149">good enough</a> for our needs.</p>