The Async Function
In the previous chapter, we learned about promises, futures, and packaged tasks. When we introduced packaged tasks, we mentioned that std::async
provides a simpler way to achieve the same result, with less code and thus being cleaner and more concise.
The async function (std::async
) is a function template that runs a callable object asynchronously where we can also select the method of execution by passing some flags defining the launch policy. It is a powerful tool for handling asynchronous operations, but its automatic management and lack of control over the thread of execution, among other aspects, can also make it unsuitable for certain tasks where fine-grained control or cancellation is required.
In this chapter, we are going to cover the following main topics:
- What is the async function and how do we use it?
- What are the different launch policies?
- What are the differences from previous methods, especially packaged tasks?
- What are the...