title: C++ - std::condition_variable notified by different threads
body: <p>I am trying to notify an event from two different threads. Main thread wakes up on first <code>notify_one()</code> call but not on the second one. Is this the right way to use condition variable?</p>
  
  <pre><code>#include &lt;chrono&gt;
  #include &lt;condition_variable&gt;
  #include &lt;iostream&gt;
  #include &lt;mutex&gt;
  #include &lt;thread&gt;
  
  bool is_ready_1(false);
  bool is_ready_2(false);
  std::mutex m;
  std::condition_variable cv;
  
  void test1()
  {
      std::this_thread::sleep_for(std::chrono::seconds(3));
      std::unique_lock&lt;std::mutex&gt; lk(m);
      is_ready_1 = true;
      cv.notify_one();
  }
  void test2()
  {
      std::this_thread::sleep_for(std::chrono::seconds(6));
      std::unique_lock&lt;std::mutex&gt; lk(m);
      is_ready_2 = true;
      cv.notify_one();
  }
  
  int main()
  {
      std::thread t1(test1);
      std::thread t2(test2);
  
      std::unique_lock&lt;std::mutex&gt; lk(m);
      while (!is_ready_1)
      {
          cv.wait(lk);
          if (is_ready_1)
              std::cout &lt;&lt; "Spurious wake-1 up!\n";
      }
  
      while (!is_ready_2)
      {
           cv.wait(lk);
           if (is_ready_2)
           std::cout &lt;&lt; "Spurious wake-2 up!\n";
      }
      t1.join(); 
      t2.join();
      system("pause");
  }
  </code></pre>