std::future<T>:: share

From cppreference.com
Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
Generic lock management
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
Safe Reclamation
Hazard Pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11) (deprecated in C++20)
(C++11) (deprecated in C++20)
Memory ordering
Free functions for atomic operations
Free functions for atomic flags
std:: shared_future < T > share ( ) noexcept ;

Transfers the shared state of * this , if any, 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 .

Parameters

(none)

Return value

A std::shared_future object containing the shared state previously held by * this , if any, constructed as if by std:: shared_future < T > ( std :: move ( * this ) ) .

Example

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
LWG 2556 C++11 share() requires valid() to be true requirement removed and made noexcept

See also

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