The std::shared_future
class template provides a means of waiting for an asynchronous result from
another thread, in conjunction with the std::promise and std::packaged_task class templates
which can be used to provide that asynchronous result. Multiple std::shared_future instances can reference
the same asynchronous result.
Instances of std::shared_future are CopyConstructible and CopyAssignable.
You can also move-construct a std::shared_future from a std::future with the same ResultType.
Accesses to a given instance of std::shared_future are not synchronized.
It is therefore not safe for multiple threads to access
the same std::shared_future instance without
external synchronization. This is in contrast to std::atomic_future. However, accesses
to the associated state are synchronized, so it is
safe for multiple threads to each access separate instances of std::shared_future that share the same
associated state without external synchronization.
template<typename ResultType> class shared_future { public: shared_future(future<ResultType>); shared_future& operator=(future<ResultType>&&); shared_future(shared_future&&); shared_future(shared_future const&); shared_future& operator=(shared_future const&); shared_future& operator=(shared_future&&); ~shared_future(); void swap(shared_future&); bool valid() const; bool is_ready() const; bool has_exception() const; bool has_value() const; see description get(); void wait(); template<typename Rep,typename Period> bool wait_for(std::chrono::duration<Rep,Period> const& relative_time); template<typename Clock,typename Duration> bool wait_until(std::chrono::time_point<Clock,Duration> const& absolute_time); };
Header
#include <future>