std::future is the standard C++ handle for receiving a one-shot value or exception computed on another thread. A recent Hacker News discussion on C++ futures part 1: The mental model (linking Raymond Chen’s article on devblogs.microsoft.com/oldnewthing) revisited the core mental model behind C++ futures. Using real programs and outputs verified on 2026-10-28 (KST) with g++ (Debian 14.2.0-19) 14.2.0 on x86_64, this post explains how std::promise, std::future, std::async, broken_promise, and wait_for work together.
Summary
std::promise is the producer side that stores a result, and std::future is the consumer side that reads it; the two are connected by a single shared state. Calling get() waits until the result is ready and rethrows any exception stored by the task. std::async creates and connects the promise automatically: std::launch::async runs the task as if on a new thread, while std::launch::deferred runs it lazily on the thread that calls get().
What are std::future and std::promise?
One-line answer: std::promise is the channel where a worker stores a value or exception, and std::future (obtained via get_future()) is the handle that reads that result from their shared state.
According to the cppreference documentation for std::promise and std::future, a std::promise stores a value or exception that is later read asynchronously through the std::future object created by get_future(). Both objects refer to the same underlying shared state. When the consumer calls future::get(), it blocks until the shared state becomes ready and then retrieves the stored result.

All three example programs below (promise_future.cpp, broken_promise.cpp, and async_policy.cpp) were built without warnings on g++ (Debian 14.2.0-19) 14.2.0 (x86_64) using g++ -std=c++20 -Wall -Wextra -pthread <file>.cpp -o <file>. Here is the complete promise_future.cpp program covering five behaviors (in the code comments: 1) another thread sets a value on the promise and main receives it via get(); 2) std::async returns a result via a future without manually creating a thread; 3) exceptions are also delivered through a future; 4) get() can be called only once, so valid() becomes false afterward; 5) wait_for bounds the waiting time) followed by its exact output.
promise_future.cpp:
#include <future>
#include <iostream>
#include <thread>
#include <stdexcept>
#include <chrono>
int main() {
// 1) promise -> future: 다른 스레드가 값을 넣고, 메인이 get()으로 받음
std::promise<int> p;
std::future<int> f = p.get_future();
std::thread t([&p] { p.set_value(42); });
std::cout << "1) promise/future get() = " << f.get() << '\n';
t.join();
// 2) std::async: 스레드를 직접 만들지 않고 결과를 future로 받음
std::future<int> a = std::async(std::launch::async, [] { return 6 * 7; });
std::cout << "2) async get() = " << a.get() << '\n';
// 3) 예외도 future로 전달됨
std::future<int> e = std::async(std::launch::async, []() -> int {
throw std::runtime_error("worker failed");
});
try { e.get(); }
catch (const std::exception& ex) { std::cout << "3) exception via get(): " << ex.what() << '\n'; }
// 4) get()은 한 번만: 두 번째 호출 전 valid()가 false
std::future<int> once = std::async(std::launch::async, [] { return 1; });
once.get();
std::cout << "4) valid() after get() = " << std::boolalpha << once.valid() << '\n';
// 5) wait_for로 기다리는 시간 제한
std::promise<void> never;
std::future<void> w = never.get_future();
auto st = w.wait_for(std::chrono::milliseconds(50));
std::cout << "5) wait_for(50ms) = " << (st == std::future_status::timeout ? "timeout" : "ready") << '\n';
}
Output:
1) promise/future get() = 42
2) async get() = 42
3) exception via get(): worker failed
4) valid() after get() = false
5) wait_for(50ms) = timeout
As shown in the first output line (1) promise/future get() = 42), the worker thread stores the value in the shared state with p.set_value(42), and the main thread retrieves it through f.get().
How does std::async differ?
One-line answer: std::async runs a function and returns a std::future without manually wiring a std::promise and std::thread, with its execution timing controlled by the launch policy.
As seen in part 2 of promise_future.cpp (2) async get() = 42), std::async directly wires the callable’s return value into a std::future<int>. According to cppreference for std::async, the launch policies work as follows:
std::launch::async: runs the function as if in a new thread.std::launch::deferred: does not spawn a thread; instead, the function is evaluated lazily in whichever thread callsget()orwait()on the future.- If no policy is specified (both flags set by default), the implementation chooses which policy to use.
Here is async_policy.cpp and its output comparing which thread executes the callable under each policy.
async_policy.cpp:
#include <future>
#include <iostream>
#include <thread>
int main() {
auto main_id = std::this_thread::get_id();
auto d = std::async(std::launch::deferred, [main_id] { return std::this_thread::get_id() == main_id; });
auto a = std::async(std::launch::async, [main_id] { return std::this_thread::get_id() == main_id; });
std::cout << std::boolalpha;
std::cout << "deferred runs on main thread: " << d.get() << '\n';
std::cout << "async runs on main thread: " << a.get() << '\n';
}
Output:
deferred runs on main thread: true
async runs on main thread: false

How are exceptions and broken promises propagated?
One-line answer: If the shared state holds an exception, future::get() rethrows it; if a std::promise is destroyed without setting a value, the shared state becomes ready with a std::future_error whose code is std::future_errc::broken_promise.
Exceptions thrown by a task travel through the shared state. In part 3 of promise_future.cpp (3) exception via get(): worker failed), the std::runtime_error("worker failed") thrown inside the task is stored in the shared state and rethrown when the main thread calls e.get().
If a std::promise is destroyed before setting a value or exception (as noted in the code comment in broken_promise.cpp: the promise goes out of scope without set_value), the shared state is automatically made ready with a std::future_error exception whose error code is std::future_errc::broken_promise. Here is broken_promise.cpp and its output.
broken_promise.cpp:
#include <future>
#include <iostream>
int main() {
std::future<int> f;
{
std::promise<int> p;
f = p.get_future();
} // set_value 없이 promise가 사라짐
try { f.get(); }
catch (const std::future_error& e) {
std::cout << "future_error: " << e.what() << '\n';
std::cout << "is broken_promise: " << std::boolalpha
<< (e.code() == std::future_errc::broken_promise) << '\n';
}
}
Output:
future_error: std::future_error: Broken promise
is broken_promise: true
What happens if you call get() twice or wait indefinitely?
One-line answer: std::future::get() can be called only once because valid() becomes false afterward, and you can bound waiting time with wait_for().
Parts 4 and 5 of promise_future.cpp illustrate these two rules:
get()can be called only once: After callingonce.get(), the future releases its reference to the shared state and4) valid() after get() = falseis printed. For multiple readers that need to access the same result, usestd::shared_future.- Bounding waits with
wait_for(): Callingw.wait_for(std::chrono::milliseconds(50))on a future whose promise has not been fulfilled returnsstd::future_status::timeout, printing5) wait_for(50ms) = timeout.
When passing a lambda to a thread, watch reference captures: [&p] in part 1 is safe because t.join() happens before p goes out of scope; for more on reference capture lifetimes, see What are C++ lambda captures? [=] vs [&] and when dangling references happen.
What are the frequently asked questions?
One-line answer: Here are answers to common questions on how std::future relates to coroutines (co_await) and std::execution, mutexes and condition variables, and std::jthread cancellation.
Is std::future the same thing as coroutines (co_await) or std::execution?
No, they are not the same thing. Coroutines (co_await) are a language feature for suspending and resuming functions, and std::execution is a separate sender/receiver execution framework; the Hacker News discussion also separates them from std::future.
Can std::future be used instead of a mutex and condition_variable?
It can replace them for a one-shot result hand-off only. For repeated synchronization or protecting shared state across multiple accesses, see Mutex vs Semaphore: How to Choose in Interviews (Korean).
How do you handle cancellation when using it with std::jthread?
Cooperative cancellation is handled via stop_token; see Using std::jthread and stop_token for Cooperative Thread Cancellation and What is C++ std::jthread? (Korean).
What related posts are worth reading?
One-line answer: These related posts cover C++ thread cancellation and lifetime, atomic operations, synchronization primitives, and lambda captures.
- Using std::jthread and stop_token for Cooperative Thread Cancellation
- What is C++ std::jthread? (Korean)
- C++ std::atomic: How to Prevent Data Races (Korean)
- Mutex vs Semaphore: How to Choose in Interviews (Korean)
- What are C++ lambda captures? [=] vs [&] and when dangling references happen
What are the sources?
One-line answer: This post is based on the Hacker News thread, the cppreference pages for std::future, std::promise, and std::async, and our local GCC verification.
- Hacker News — “C++ futures part 1: The mental model” (Raymond Chen, devblogs.microsoft.com/oldnewthing) (checked 2026-10-28)
- cppreference — std::future (checked 2026-10-28)
- cppreference — std::promise (checked 2026-10-28)
- cppreference — std::async (checked 2026-10-28)
- Reproduction environment:
g++ (Debian 14.2.0-19) 14.2.0, x86_64 (checked 2026-10-28 KST)