title: Why would concurrency using std::async be faster than using std::thread?
body: <p>I was reading Chapter 8 of the &quot;Modern C++ Programming Cookbook, 2nd edition&quot; on concurrency and stumbled upon something that puzzles me.</p>
  <p>The author implements different versions of parallel map and reduce functions using <code>std::thread</code> and <code>std::async</code>. The implementations are really close; for example, the heart of the <code>parallel_map</code> functions are</p>
  <pre><code>// parallel_map using std::async
  ...
  tasks.emplace_back(std::async(
    std::launch::async,
    [=, &amp;f] {std::transform(begin, last, begin, std::forward&lt;F&gt;(f)); }));
  ...
  
  // parallel_map using std::thread
  ...
  threads.emplace_back([=, &amp;f] {std::transform(begin, last, begin, std::forward&lt;F&gt;(f)); });
  ...
  </code></pre>
  <p>The complete code can be found <a href="https://raw.githubusercontent.com/PacktPublishing/Modern-CPP-Programming-Cookbook-Second-Edition/master/Chapter08/recipe_8_09.h" rel="noreferrer">here</a> for <code>std::thread</code> and <a href="https://raw.githubusercontent.com/PacktPublishing/Modern-CPP-Programming-Cookbook-Second-Edition/master/Chapter08/recipe_8_10.h" rel="noreferrer">there</a> for <code>std::async</code>.</p>
  <p>What puzzles me is that the computation times reported in the book give a significant and consistent advantage to the <code>std::async</code> implementation. Moreover, the author acknowledge this fact as being obvious, without providing any hint of justification:</p>
  <blockquote>
  <p>If we compare this [result with async] with the results from the parallel version using threads, we will find that these are faster execution times and that the speedup is significant, especially for the <code>fold</code> function.</p>
  </blockquote>
  <p>I ran the code above on my computer, and even though the differences are not as compelling as in the book, I find that the <code>std::async</code> implementation is indeed faster than the <code>std::thread</code> one. (The author also later brings in standard implementations of these algorithms, which are even faster). On my computer, the code runs with four threads, which corresponds to the number of physical cores of my CPU.</p>
  <p>Maybe I missed something, but why is it obvious that <code>std::async</code> should run faster than <code>std::thread</code> on this example? My intuition was that <code>std::async</code> being a higher-level implementation of threads, it should take at least the same amount of time, if not more, than threads -- obviously I was wrong. Are those findings consistent, as suggested by the book, and what is the explanation?</p>