Futures, Promises, and Async
In the previous section, we learned almost all that we need to work with threads. But we still have something interesting to consider, that is, synchronizing threads using future results. When we considered condition variables, we didn't cover the second type of synchronization with future results. Now, it's time to learn about that.
Suppose there is a situation wherein we run some thread and continue with other work. When we need a result, we stop and check if it is ready. This situation describes the actual work with future results. In C++, we have a header file called <future> that contains two template classes which represent future results: std::future<> and std::shared_future<>. We use std::future<> when we need a single future result and use std::shared_future<> when we need multiple valid copies. We can compare them with std::unique_ptr and std::shared_ptr.
To work with future results, we need a special mechanism...