std::promise<R>::get_future

< cpp‎ | thread‎ | promise
std::future<R> get_future();
(C++11 起)

返回与 *this 关联同一状态的未来体对象。

*this 无共享状态或已调用 get_future,则抛出异常。可使用 std::future::share 以获取承诺体-未来体交流通道的多个“弹出”端。

对此函数的调用与对 set_valueset_exceptionset_value_at_thread_exitset_exception_at_thread_exit 的调用不造成数据竞争(但它们不必彼此同步)。

参数

(无)

返回值

指代 *this 的共享状态的未来体。

异常

遇到下列条件时抛出 std::future_error

  • *this 无共享状态。设置错误码为 no_state
  • 已在与 *this 拥有同一共享状态的承诺体上调用过 get_future()。设置错误码为 future_already_retrieved