hpx::promise#

Defined in header hpx/future.hpp.

See Public API for a list of names and headers that are part of the public HPX API.

template<typename R, typename Allocator>
struct uses_allocator<hpx::promise<R>, Allocator> : public true_type#
namespace hpx

Top level HPX namespace.

template<typename R>
class promise : public hpx::detail::promise_base<R>#
#include <promise.hpp>

The class template hpx::promise provides a facility to store a value or an exception that is later acquired asynchronously via a hpx::future object created by the hpx::promise object. Note that the hpx::promise object is meant to be used only once. Each promise is associated with a shared state, which contains some state information and a result which may be not yet evaluated, evaluated to a value (possibly void) or evaluated to an exception. A promise may do three things with the shared state:

  • make ready: the promise stores the result or the exception in the shared state. Marks the state ready and unblocks any thread waiting on a future associated with the shared state.

  • release: the promise gives up its reference to the shared state. If this was the last such reference, the shared state is destroyed. Unless this was a shared state created by hpx::async which is not yet ready, this operation does not block.

  • abandon: the promise stores the exception of type hpx::future_error with error code hpx::error::broken_promise, makes the shared state ready, and then releases it. The promise is the “push” end of the promise-future communication channel: the operation that stores a value in the shared state synchronizes-with (as defined in hpx::memory_order) the successful return from any function that is waiting on the shared state (such as hpx::future::get). Concurrent access to the same shared state may conflict otherwise: for example multiple callers of hpx::shared_future::get must either all be read-only or provide external synchronization.

Public Functions

promise() = default#
template<typename Allocator>
inline promise(std::allocator_arg_t, Allocator const &a)#
promise(promise &&other) noexcept = default#
promise(promise const &other) = delete#
~promise() = default#
promise &operator=(promise &&other) noexcept = default#
promise &operator=(promise const &other) = delete#
inline void swap(promise &other) noexcept#
inline void set_value(R const &r)#
inline void set_value(R &&r)#
template<typename ...Ts>
inline void set_value(Ts&&... ts)#

Private Types

using base_type = detail::promise_base<R>#
template<typename R>
class promise<R&> : public hpx::detail::promise_base<R&>#

Public Functions

promise() = default#
template<typename Allocator>
inline promise(std::allocator_arg_t, Allocator const &a)#
promise(promise &&other) noexcept = default#
promise(promise const &other) = delete#
~promise() = default#
promise &operator=(promise &&other) noexcept = default#
promise &operator=(promise const &other) = delete#
inline void swap(promise &other) noexcept#
inline void set_value(R &r)#

Private Types

using base_type = detail::promise_base<R&>#
template<>
class promise<void> : public hpx::detail::promise_base<void>#

Public Functions

promise() = default#
template<typename Allocator>
inline promise(std::allocator_arg_t, Allocator const &a)#
promise(promise &&other) noexcept = default#
promise(promise const &other) noexcept = delete#
~promise() = default#
promise &operator=(promise &&other) noexcept = default#
promise &operator=(promise const &other) noexcept = delete#
inline void swap(promise &other) noexcept#
inline void set_value()#

Private Types

using base_type = detail::promise_base<void>#
namespace lcos
namespace local
namespace std

Functions

template<typename R>
void swap(hpx::promise<R> &x, hpx::promise<R> &y) noexcept#
template<typename R, typename Allocator> promise< R >, Allocator > : public true_type