title: condition variable timeout not understood
body: <p>I am playing to try to give a timeout to a thread.
  I try to use <a href="http://it.cppreference.com/w/cpp/thread/condition_variable/wait_for" rel="nofollow">std::condition_variable::wait_for</a> but this behaves differently than I would expect.</p>
  
  <p>Here my simple code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;thread&gt;
  #include &lt;chrono&gt;
  #include &lt;mutex&gt;
  #include &lt;condition_variable&gt;
  
  std::mutex myMutex;
  
  void waitSec(int seconds)
  {
      std::cout &lt;&lt;"t1 start" &lt;&lt;std::endl;
      std::unique_lock&lt;std::mutex&gt; lock(myMutex);
      std::this_thread::sleep_for(std::chrono::seconds(seconds));
      std::cout &lt;&lt;"t1 end" &lt;&lt;std::endl;
  }
  
  int main(void)
  {
      // launch thread that sleeps 10s
      std::thread t1(waitSec,10);
      std::this_thread::sleep_for(std::chrono::seconds(1));
  
      // wait for lock during max 1 second
      std::condition_variable* conditionVariable = new std::condition_variable();
      std::cout &lt;&lt; "before" &lt;&lt; std::endl;
      std::unique_lock&lt;std::mutex&gt; lock(myMutex);
      conditionVariable-&gt;wait_for(lock,std::chrono::seconds(1));
      std::cout &lt;&lt; "after" &lt;&lt; std::endl;
  
      t1.join();
  }
  </code></pre>
  
  <p>I expect Thread T1 to sleeps for 10 seconds. Since I give 1s timeout to the <code>wait_for</code> in the main thread I would expect that <code>after</code> is printed before <code>t1 end</code>. </p>
  
  <p>What happens instead is that t1 runs for 10 seconds, (printing <code>t1 end</code>) and just 1s after <code>after</code> is printed.</p>
  
  <p>Can you explain me why it behaves like this and what should I do to get my timeout performing as a timeout?</p>