title: How to sleep() a thread in C++
body: <p>I'm making a simple program that creates a thread, sleeps for 20 seconds, then terminates the thread. The code below compiles, but fails to sleep and crashes at runtime (after all cout lines are run). I'm not sure what is wrong, I've tried to emulate other threads (ha) on this topic as best I can. Is there a different approach I should be using? Using Windows 10</p>
  
  <pre><code>    #include "stdafx.h"
      #include &lt;iostream&gt;      
      #include &lt;thread&gt;
      #include &lt;Windows.h&gt;
  
      using namespace std;
  
      void t1(int x)
      {
          cout &lt;&lt; "Child greeting!\n";
          Sleep(20000);
          cout &lt;&lt; "Child terminating!\n";
          std::terminate();
      }
  
      int main()
      {
          cout &lt;&lt; "Parent greeting!\n";
          thread first(t1,0);
          cout &lt;&lt; "Parent terminating!\n";
  
          return 0;
      }
  </code></pre>