CoopSync for TBB 0.1.0
Cooperative synchronization primitives for TBB resumable tasks
Loading...
Searching...
No Matches
coopsync_tbb::shared_future< T > Class Template Reference

Copyable future that allows retrieving the result multiple times. More...

#include <coopsync_tbb/future.hpp>

Public Member Functions

 shared_future () noexcept=default
 Constructs an invalid shared_future.
 shared_future (const shared_future &other) noexcept=default
 The shared_future is copy-constructible.
shared_future & operator= (const shared_future &other) noexcept=default
 The shared_future is copy-assignable.
 shared_future (shared_future &&other) noexcept=default
 The shared_future is move-constructible.
shared_future & operator= (shared_future &&other) noexcept=default
 The shared_future is move-assignable.
 ~shared_future ()=default
 Destroys the shared_future releasing any shared state.
bool valid () const noexcept
 Tests whether the shared_future is valid and refers to a shared state.
bool try_wait () const
 Checks whether the shared state is ready without suspending.
void wait () const
 Suspends the current task until the shared state is ready.
const T & get () const
 Obtains a reference to the value stored in the shared state. If the shared state is ready, this function returns immediately. Otherwise, the task is suspended until the state becomes ready. This function can be called multiple times without invalidating the shared state.

Friends

template<typename U>
class future

Detailed Description

template<typename T>
class coopsync_tbb::shared_future< T >

Copyable future that allows retrieving the result multiple times.

Unlike future, shared_future does not consume the shared state when get() is called.

Template Parameters
TThe type of the value stored in the shared state.

Constructor & Destructor Documentation

◆ shared_future() [1/2]

template<typename T>
coopsync_tbb::shared_future< T >::shared_future ( const shared_future< T > & other)
defaultnoexcept

The shared_future is copy-constructible.

Parameters
otherThe shared_future to copy from, after copying both objects refer to the same shared state.

◆ shared_future() [2/2]

template<typename T>
coopsync_tbb::shared_future< T >::shared_future ( shared_future< T > && other)
defaultnoexcept

The shared_future is move-constructible.

Parameters
otherThe shared_future to move from, after construction has no shared state and is not valid.

Member Function Documentation

◆ get()

template<typename T>
const T & coopsync_tbb::shared_future< T >::get ( ) const
inline

Obtains a reference to the value stored in the shared state. If the shared state is ready, this function returns immediately. Otherwise, the task is suspended until the state becomes ready. This function can be called multiple times without invalidating the shared state.

Returns
A const reference to the stored value.
Exceptions
future_errorif not valid or if the promise is broken.
Anyexception stored in the shared state.

◆ operator=() [1/2]

template<typename T>
shared_future & coopsync_tbb::shared_future< T >::operator= ( const shared_future< T > & other)
defaultnoexcept

The shared_future is copy-assignable.

Parameters
otherThe shared_future to copy from, after assignment both objects refer to the same shared state.

◆ operator=() [2/2]

template<typename T>
shared_future & coopsync_tbb::shared_future< T >::operator= ( shared_future< T > && other)
defaultnoexcept

The shared_future is move-assignable.

Parameters
otherThe shared_future to move from, after assignment has no shared state and is not valid.

◆ try_wait()

template<typename T>
bool coopsync_tbb::shared_future< T >::try_wait ( ) const
inline

Checks whether the shared state is ready without suspending.

Returns
true if the shared state is ready, false otherwise.
Exceptions
future_errorwith std::future_errc::no_state if not valid.

◆ valid()

template<typename T>
bool coopsync_tbb::shared_future< T >::valid ( ) const
inlinenoexcept

Tests whether the shared_future is valid and refers to a shared state.

Returns
true if the shared_future is valid, false otherwise.

◆ wait()

template<typename T>
void coopsync_tbb::shared_future< T >::wait ( ) const
inline

Suspends the current task until the shared state is ready.

Exceptions
future_errorwith std::future_errc::no_state if not valid.

The documentation for this class was generated from the following file: