Article

C++ futures part 2: The mental model for std::promise, std::packaged_task

The Old New Thing ·The Old New Thing ·Published 2026-10-13 ·5 min read

This article explores the usage and management of the 'state' in C++ futures, specifically focusing on std::promise and std::packaged_task. It explains how these components interact and manage the lifetime of the source object.

From the article

Last time , we looked at the “state” that powers the std::promise , std::packaged_task , std::async , std::future , and std::shared future classes. Now we’ll see how that “state” (which I call the source ) gets used and passed around.

The lifetime of the source is managed by a std:: shared_ ptr<source<T>> . Everybody who has a reference to the source uses this shared pointer.

The simplest case is std::promise . The operations on std::promise pretty much map directly to the operations on the source we laid out last time.


Share this resource


Discovered 2026-10-14 Source The Old New Thing Archive 2026-10 →