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.
GoKawiil's interpretation of the reporting above, not reported fact.
The explanation targets C++ developers who want to understand the thread-safety guarantees and error conditions (like calling set_value twice) built into the standard library's async primitives. By exposing the internal state machine, Chen's post could help engineers debug or reason about future-based concurrency code more confidently, though this is the first part of a series with further mechanics like thread-exit value setting still to come.
- std::promise, std::future and related types share a common internal 'state' object, which the author labels the 'source'
- The source tracks whether it holds nothing, a value, an exception, or a consumed result, using a mutex and condition variable for thread safety
- Setting a value or exception is only allowed once; repeated attempts trigger a future_error exception
Source: devblogs.microsoft.com — Raymond Chen, 2026-10-19
Published there as: “C++ futures part 1: The mental model”
Read the original report → The summary and analysis above are GoKawiil's own, written from reporting by the source above. Facts and quotes belong to the original publisher.