Raymond Chen breaks down the internals of C++'s std::future family
In a new blog post, Microsoft engineer Raymond Chen explains how std::promise, std::packaged_task, std::async, std::future and std::shared_future are all built on a shared internal construct, which he calls the 'source'. He walks through a simplified implementation showing how this source uses a discriminant, a union, a mutex and a condition variable to store a value or exception, enforce single-assignment rules, and let waiting threads be notified when a result becomes available.