← Wednesday, October 14, 2026Languages & toolsDeep dive

C++ promises and packaged tasks share a reference-counted state

devblogs.microsoft.com by Raymond Chen Editor score 7/10

The explanation models futures around a shared source object: promises fill it, while packaged tasks store a callable whose result or exception is later retrieved through a future. This mental model helps engineers reason about asynchronous value flow and object lifetimes in C++.

What
C++ std::packaged_task stores a callable and uses shared state, called the source, to pass its result to a future.
How
Invoking the task calls the stored callable and puts its value or exception in the source object, where the future can retrieve it.
Why it matters
The shared-state model clarifies how asynchronous work transfers results or exceptions between components in C++ programs.
invokes value or exce… retrieves std::packaged_t… callable source<T> std::future
A packaged task invokes its callable and stores the outcome for a future to retrieve. Sketched from the article's own text.

Discussion

Discussion is not switched on yet. Use Note above to keep your own thoughts on this story.

Headline, summary, brief and diagram are written by a model from the source's own text; the link, byline and numbers come from the source. Read the original before relying on a claim.

Your note

Private to you. Stored in this browser, and synced to your account when you are signed in.