title: Microsoft VC++ PPL and sleeping
body: <p>Following program  runs differently depending on the sleep mechanism used. </p>
  
  <pre><code>#include &lt;ppltasks.h&gt;
  #include &lt;chrono&gt;
  #include &lt;thread&gt;
  #include &lt;iostream&gt;
  #include &lt;atomic&gt;
  #include &lt;windows.h&gt;
  using namespace std;
  #define MODERN_MAN
  int main()
  {
      atomic&lt;int&gt; cnt;
      concurrency::task_group tg;
      for (int i =0; i&lt;1000; ++i )
      {
          tg.run([&amp;cnt](){cout &lt;&lt; "."; cnt++; 
          #ifdef MODERN_MAN
          this_thread::sleep_for(chrono::seconds(5));
          #else
          Sleep(5000);
          #endif
          });
      }
      tg.wait();
      cout &lt;&lt; cnt;
      return 0;
  }
  </code></pre>
  
  <p>Difference is that with <code>sleep_for</code> from what I see tasks get scheduled in a way that 1 sleeping doesnt prevent others from running. </p>
  
  <p>With <code>Sleep</code> from what I see they block further tasks from running. </p>
  
  <p>My questions are:<br>
  a) how can PPL thread pool do the clever trick that enables it to workaround <code>sleep_for</code> ( I thought it is a system call that tells OS (put this thread in the list of inactive threads for x seconds)  </p>
  
  <p>b) Is the behavior Im seeing here with <code>sleep_for</code> guaranteed(aka is it defined that I wont get same behavior as with <code>Sleep</code>) </p>