title: What's the correct way to deal with spurious wakeups, in general?
body: <p>Among the options below, is there any correct way to deal with spurious wakeups when using conditional variables? </p>
  
  <p>1) Put the <code>wait(unique_lock_ul)</code> into an infinite <code>while</code> loop, using a boolean</p>
  
  <pre><code>unique_lock&lt;mutex&gt; ul(m); 
  while(!full)
    cv.wait(ul);
  </code></pre>
  
  <p>2) Same with if</p>
  
  <pre><code>unique_lock&lt;mutex&gt; ul(m); 
  if(!full)
    cv.wait(ul);
  </code></pre>
  
  <p>3) Put a condition inside the <code>wait()</code>, for example by using lambda functions</p>
  
  <pre><code>unique_lock&lt;mutex&gt; ul(m); 
  cv.wait(ul, [&amp;](){return !full;});
  </code></pre>
  
  <p>If none of this is correct, how does one deal with spurious wakeups easily?</p>
  
  <p>I'm rather new to conditional variables in C++ and I'm not sure if some of the code I read deals with the case of spurious wakeups or not.</p>