
Modern C++ Programming Cookbook
By :

Tasks are a higher-level alternative to threads for performing concurrent computations. std::async()
enables us to execute functions asynchronously, without the need to handle lower-level threading details. In this recipe, we will take the same task of implementing a parallel version of the map
and fold
functions, as in the previous recipe, but we will use tasks and see how it compares with the thread version.
The solution presented in this recipe is similar in many aspects to the one that uses threads in the previous recipe, Implementing parallel map and fold with threads. Make sure you read that one before continuing with the current recipe.
To implement a parallel version of the map
function, do the following:
template <typename Iter, typename F> void parallel_map(Iter begin,...