Tasks
Explore how Modern C++ tasks simplify asynchronous programming by using futures and promises for communication. Understand the differences between threads and tasks, learn how tasks handle results and exceptions safely, and discover why tasks provide better concurrency abstractions in embedded systems and other safety-critical applications.
We'll cover the following...
Introduction
Tasks were one of the latest additions to the C++11 standard, and they offer a better abstraction than threads.
In addition to threads, C++ has tasks to perform work asynchronously. Tasks need the <future> header. A task will be parameterized with a work package, and it consists of the two associated components: a promise and a future. Both are connected via data channel.
The promise executes the work packages and puts the result in the data channel. The associated future picks up the result. Both communication endpoints can run in separate threads. What is special is that the future can pick up the result at a later time, meaning that ...