std::future::share

From cppreference.com
< cpp‎ | thread‎ | future
 
 
Thread support library
Threads
(C++11)
this_thread namespace
(C++11)
(C++11)
(C++11)
(C++11)
Mutual exclusion
(C++11)
(C++11)
(C++17)
Generic lock management
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
(C++11)
(C++11)
Condition variables
(C++11)
Futures
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
 
 
std::shared_future<T> share();

Transfers the shared state of *this to a std::shared_future object. Multiple std::shared_future objects may reference the same shared state, which is not possible with std::future.

After calling share on a std::future, valid() == false.

The behavior is undefined if valid()== false before the call to this function.

Contents

[edit] Parameters

(none)

[edit] Return value

A std::shared_future object containing the shared state previously held by *this

[edit] Notes

The implementations are encouraged to detect the case when valid == false before the call and throw a future_error with an error condition of future_errc::no_state.

[edit] Example

[edit] See also

waits for a value (possibly referenced by other futures) that is set asynchronously
(class template)