title: Why do you need a while loop while waiting for a condition variable
body: <p>Say you have this code</p>
  
  <pre><code>pthread_mutex_lock(&amp;cam-&gt;video_lock);
  while(cam-&gt;status == WAIT_DISPLAY) // &lt;-- Why is this a 'while' and not an 'if'?
      pthread_cond_wait(&amp;cam-&gt;video_cond, &amp;cam-&gt;video_lock);
  pthread_mutex_unlock(&amp;cam-&gt;video_lock);
  </code></pre>
  
  <p>My question is, why do you need a while loop here. Wouldn't <strong>pthread_cond_wait</strong> just wait until the signalling thread signals <strong>cam_video_cond</strong>? OK, I know you might have a case where <strong>cam->status</strong> is not equal to <strong>WAIT_DISPAY</strong> when <strong>pthread_cond_wait</strong> is called, but in that case you could just check it through an <strong>if</strong> condition rather than using <strong>while</strong>. </p>
  
  <p>Am I missing something here? My understanding of <strong>pthread_cond_wait</strong> is that it just waits for infinite if <strong>cam_video_cond</strong> is not signalled. Moreover, it unlocks the <strong>cam_video_lock</strong> mutex when called, but when the condition is signalled, before returning, it relocks <strong>cam_video_lock</strong>. Am I right?</p>