std::promise<R>::set_value_at_thread_exit
Min standard notice:
Stores the value into the shared state without making the state ready immediately. The state is made ready when the current thread exits, after all variables with thread-local storage duration have been destroyed.
# Declarations
Main template
void set_value_at_thread_exit( const R& value );
(since C++11)
void set_value_at_thread_exit( R&& value );
(since C++11)
std::promise<R&> specializations
void set_value_at_thread_exit( R& value );
(since C++11)
std::promise<void> specialization
void set_value_at_thread_exit();
(since C++11)
# Parameters
value: value to store in the shared state
# Return value
(none)
# Example
#include <future>
#include <iostream>
#include <thread>
int main()
{
using namespace std::chrono_literals;
std::promise<int> p;
std::future<int> f = p.get_future();
std::thread([&p]
{
std::this_thread::sleep_for(1s);
p.set_value_at_thread_exit(9);
}).detach();
std::cout << "Waiting... " << std::flush;
f.wait();
std::cout << "Done!\nResult is: " << f.get() << '\n';
}
# Defect reports
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 2098 | C++11 | it was unclear which exceptions are required to be thrown | made clear |