Tasks
In addition to threads, C++ has tasks to perform work asynchronously. Tasks need the header <future>
. A task is parameterised with a work package and consists of the two associated components, a promise and a future. Both are connected via a 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’s special is that the future can pick up the result at a later time. Therefore the calculation of the result by the promise is independent of the query of the result by the associated future.
Threads versus Tasks
Threads are very different from tasks.
For the communication between the creator thread and the created thread, you have to use a shared variable...