shared_future Class

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

Describes an asynchronous return object. In contrast with a future object, an asynchronous provider can be associated with any number of shared_future objects.

template <class Ty>
class shared_future;

Do not call any methods other than valid, operator=, and the destructor on a shared_future object that's empty.

shared_future objects are not synchronized. Calling methods on the same object from multiple threads introduces a data race that has unpredictable results.

Public Constructors

NameDescription
shared_future::shared_future ConstructorConstructs a shared_future object.

Public Methods

NameDescription
shared_future::get MethodRetrieves the result that's stored in the associated asynchronous state.
shared_future::valid MethodSpecifies whether the object is not empty.
shared_future::wait MethodBlocks the current thread until the associated asynchronous state is ready.
shared_future::wait_for MethodBlocks until the associated asynchronous state is ready or until the specified time has elapsed.
shared_future::wait_until MethodBlocks until the associated asynchronous state is ready or until a specified point in time.

Public Operators

NameDescription
shared_future::operator=Assigns a new associated asynchronous state.

Header: future

Namespace: std

Retrieves the result that's stored in the associated asynchronous state.

const Ty& get() const;

Ty& get() const;

void get() const;

Remarks

If the result is an exception, the method rethrows it. Otherwise, the result is returned.

Before it retrieves the result, this method blocks the current thread until the associated asynchronous state is ready.

For the partial specialization shared_future<Ty&>, the stored value is effectively a reference to the object that was passed to the asynchronous provider as the return value.

Because no stored value exists for the specialization shared_future<void>, the method returns void.

Transfers an associated asynchronous state from a specified object.

shared_future& operator=(shared_future&& Right) noexcept;
shared_future& operator=(const shared_future& Right);

Parameters

Right
A shared_future object.

Return Value

*this

Remarks

For the first operator, Right no longer has an associated asynchronous state after the operation.

For the second method, Right maintains its associated asynchronous state.

Constructs a shared_future object.

shared_future() noexcept;
shared_future(future<Ty>&& Right) noexcept;
shared_future(shared_future&& Right) noexcept;
shared_future(const shared_future& Right);

Parameters

Right
A future or shared_future object.

Remarks

The first constructor constructs a shared_future object that has no associated asynchronous state.

The second and third constructors construct a shared_future object and transfer the associated asynchronous state from Right. Right no longer has an associated asynchronous state.

The fourth constructor constructs a shared_future object that has the same associated asynchronous state as Right.

Specifies whether the object has an associated asynchronous state.

bool valid() noexcept;

Return Value

true if the object has an associated asynchronous state; otherwise, false.

Blocks the current thread until the associated asynchronous state is ready.

void wait() const;

Remarks

An associated asynchronous state is ready only if its asynchronous provider has stored a return value or stored an exception.

Blocks the current thread until the associated asynchronous state is ready or until a specified time has elapsed.

template <class Rep, class Period>
future_status wait_for(
    const chrono::duration<Rep, Period>& Rel_time) const;

Parameters

Rel_time
A chrono::duration object that specifies a maximum time interval that the thread blocks.

Return Value

A future_status that indicates the reason for returning.

Remarks

An associated asynchronous state is ready only if its asynchronous provider has stored a return value or stored an exception.

Blocks the current thread until the associated asynchronous state is ready or until after a specified time point.

template <class Clock, class Duration>
future_status wait_until(
    const chrono::time_point<Clock, Duration>& Abs_time) const;

Parameters

Abs_time
A chrono::time_point object that specifies a time after which the thread can unblock.

Return Value

A future_status that indicates the reason for returning.

Remarks

An associated asynchronous state is ready only if its asynchronous provider has stored a return value or stored an exception.

Header Files Reference
<future>

Show: