How do promise, future, shared_future, and async communicate values and exceptions, and what lifecycle traps matter?
Show answer and explanation
A promise owns the producer side of a one-shot shared state and can make either a value or exception ready; abandoning it without a result makes a waiting future observe broken_promise. A future is move-only and get() consumes its result, while shared_future is copyable and permits repeated observation with appropriate synchronization for the value itself. std::async creates a future but, unless a launch policy is specified, may run asynchronously or defer execution until a wait. Destruction of the last future associated with an asynchronously launched task can wait for completion, so ownership, cancellation, exception observation, and shutdown must be deliberate.
A promise owns the producer side of a one-shot shared state and can make either a value or exception ready; abandoning it without a result makes a waiting future observe broken_promise. A future is move-only and get() consumes its result, while shared_future is copyable and permits repeated observation with appropriate synchronization for the value itself. std::async creates a future but, unless a launch policy is specified, may run asynchronously or defer execution until a wait. Destruction of the last future associated with an asynchronously launched task can wait for completion, so ownership, cancellation, exception observation, and shutdown must be deliberate.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.