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