Add mechanism to finalize promise and wait and/or produce associated future

Issue #91 resolved
Amir Kamil created an issue

We expect the following to be a common pattern:

promise<> prom;
for (...) {
  some_comm_op(..., prom);
}
prom.finalize_anonymous();
wait(prom.get_future());

We suspect that users will often forget the finalize_anonymous() call and then have to debug why their code is not working. We should provide a mechanism that reduces the possibilities of this. Some options:

  • add a promise<T...>::finalize_and_get_future() method and then check in debug mode that this is only called once on a given promise
  • add a scope-based mechanism to do both the finalization and wait:
{
  scoped_promise prom; // not a template since this pattern is only on empty promises
  for (...) {
    some_comm_op(..., prom);
  }
} // finalizes and waits on prom

Comments (5)

  1. BrianS

    What happens when you get_future() then resume adding that promise to new comm ops? That's not legal, right?

  2. Dan Bonachea

    @bvstraalen: promise::get_future() is a const method with no preconditions, and may be called on any valid promise object at any time.

    The operation requested in this issue is the following method added in the current Generalized Completion branch:

     template < typename ...T>
     future <T... > promise <T... >:: finalize ();
    
    Equivalent to calling this->fulfill_anonymous(1) and then returning the result of this->get_future().
    
  3. Log in to comment