Summary
In this chapter, we learned about std::async
, how to use this function to execute asynchronous tasks, how to define its behavior by using launch policies, and how to handle exceptions.
We also now understand how the futures returned by the async function can impact performance and how to use them wisely. Also, we saw how to limit the number of asynchronous tasks by the number of available threads in the system by using counting semaphores.
We also mentioned some scenarios where std::async
might not be the best tool for the job.
Finally, we implemented several examples covering real-life scenarios, which is useful for parallelizing many common tasks.
With all the knowledge acquired in this chapter, now we know when (and when not) to use the std::async
function to run asynchronous tasks in parallel, improving the overall performance of applications, achieving better computer resource usage, and reducing resource exhaustion.
In the next chapter, we will learn how...