public member function


generic template (1)
void set_value_at_thread_exit (const T& val);void set_value_at_thread_exit (T&& val);
specializations (2)
void promise<R&>::set_value_at_thread_exit (R& val);     // when T is a reference type (R&)void promise<void>::set_value_at_thread_exit (void);     // when T is void
Set value at thread exit
Stores val as the value in the shared state without making it ready immediately. Instead, it will be made ready automatically at thread exit, once all objects of thread storage duration have been destroyed.

If a future object that is associated to the same shared state is waiting on a call to future::get, it stays blocked until the thread ends. Once the thread ends, it unblocks and returns val.

Notice that calling this function already sets the value in the shared state, and any call that attempts to modify this value between this call and the end of the thread will throw future_error with promise_already_satisfied as error condition.


The value for the shared state.

Return value


Data races

The promise object is modified.
The shared state is modified as an atomic operation (causing no data races), with synchronization happening at thread end.

Exception safety

Basic guarantee: if an exception is thrown, the promise object is in a valid state.

This member function throws an exception on the following conditions:
exception typeerror conditiondescription
future_errorfuture_errc::no_stateThe object has no shared state (it was moved-from)
future_errorfuture_errc::promise_already_satisfiedThe shared state already has a stored value or exception
This member function also throws if the constructor selected to copy/move val throws (for (1)) and -depending on the library implementation- may also throw to report other situations.

See also