title: Efficiently wait for a flag state change without blocking resources?
body: <p>Thread to wait <strong>infinitely</strong> in a loop until a <strong>flag state</strong> change, then call function.</p>
  
  <p><strong>pseudo code illustration:</strong></p>
  
  <pre><code>while (true)
  {
      while (!flag)
      {
              sleep(1);
      }
      clean_upfunction();
  }
  </code></pre>
  
  <p><strong>Currently</strong>:</p>
  
  <ul>
  <li>Using the multithreaded versions of the <a href="http://msdn.microsoft.com/en-us/library/abx4dbyh(VS.80).aspx" rel="nofollow noreferrer"><b>C run-time libraries only</b></a></li>
  </ul>
  
  <p><strong>No:</strong></p>
  
  <ul>
  <li>MFC</li>
  </ul>
  
  <p><strong>Question:</strong></p>
  
  <ul>
  <li>Is there a more efficient way of implementing the above</li>
  <li>A waitForStateChange() - similar to above - in the threading library </li>
  </ul>