hpx::distributed::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 Result, typename RemoteResult>
class promise#

A promise can be used by a single thread to invoke a (remote) action and wait for the result. The result is expected to be sent back to the promise using the LCO’s set_event action

A promise is one of the simplest synchronization primitives provided by HPX. It allows to synchronize on a eager evaluated remote operation returning a result of the type Result. The promise allows to synchronize exactly one thread (the one passed during construction time).

// Create the promise (the expected result is a id_type)
hpx::distributed::promise<hpx::id_type> p;

// Get the associated future
future<hpx::id_type> f = p.get_future();

// initiate the action supplying the promise as a
// continuation
apply<some_action>(new continuation(p.get_id()), ...);

// Wait for the result to be returned, yielding control
// in the meantime.
hpx::id_type result = f.get();
// ...

Note

The action executed by the promise must return a value of a type convertible to the type as specified by the template parameter RemoteResult

Template Parameters
  • Result – The template parameter Result defines the type this promise is expected to return from promise::get.

  • RemoteResult – The template parameter RemoteResult defines the type this promise is expected to receive from the remote action.