June 2017
Intermediate to advanced
532 pages
12h 59m
English
If we would not have used std::async the serial unparallelized code could have looked as simple as that:
auto hist (histogram(input));auto sorted_str (sorted( input));auto vowel_count (vowels( input));for (const auto &[c, count] : hist) { cout << c << ": " << count << '\n';}cout << "Sorted string: " << quoted(sorted_str) << '\n';cout << "Total vowels: " << vowel_count << '\n';
The only thing we did in order to parallelize the code was the following. We wrapped the three function calls into async(launch::async, ...) calls. This way these three functions are not executed by the main thread we are currently running in. Instead, async starts new threads and lets them execute the functions concurrently. This way we get to execute ...
Read now
Unlock full access