future::result*() should assert readiness

Issue #389 resolved
Dan Bonachea created an issue

The functions future<T...>::result{,_tuple,_reference} all carry a precondition of this->ready(). However, the implementation does not currently assert this trivially checkable property. This allows incorrect programs that call result() on a non-ready future to silently stray into UB in a DEBUG build, where we can/should produce an explanatory fatal error message instead.

Based on evidence from the user-support forum, this has been a problem for real users in the field, so I'll be addressing it before the next release.

Comments (3)

  1. Dan Bonachea reporter

    Fix issue #389: future::result*() should assert readiness

    Add the missing assertions

    Sample failure output:

    //////////////////////////////////////////////////////////////////////
    UPC++ assertion failure:
     on process 0 (pcp-d-10)
     at <redacted>/include/upcxx/future/future1.hpp:147
    
    Called future::result() on a non-ready future, which has undefined behavior.
    Please call future::wait() instead, which blocks invoking progress until readiness, and then returns the result.
    Alternatively, use future::then(...) to schedule an asynchronous callback to execute after the future is readied.
    
    To have UPC++ freeze during these errors so you can attach a debugger,
    rerun the program with GASNET_FREEZE_ON_ERROR=1 in the environment.
    //////////////////////////////////////////////////////////////////////
    

    → <<cset 8bf1c3474133>>

  2. Dan Bonachea reporter

    Merge pull request #231 into develop

    • assert-preconditions: Update ChangeLog persona: Enforce the threadmode=seq restriction on master persona ownership Add some missing assertions to enforce THREADMODE=seq restrictions Improve assertions for master persona diagnostic: Add function name information to fatal errors and asserts memory kinds: Fix several assertions VIS: minor tweaks to assertions misc: add some missing assertions for master persona rpc(_ff): assert validity of recipient argument broadcast/reduce_one: Assert valid root rank Add precondition assertions to {team_id,dist_id}::here() teams: Assert preconditions on rank translation Update ChangeLog Fix issue #389: future::result*() should assert readiness Use gasnett_fatalerror_nopos when available

    → <<cset f9f97ce91f67>>

  3. Log in to comment