命名空间
变体
操作

std::promise<R>::get_future

来自 cppreference.cn
< cpp‎ | thread‎ | promise
 
 
并发支持库
线程
(C++11)
(C++20)
this_thread 命名空间
(C++11)
(C++11)
(C++11)
协同取消
互斥
(C++11)
通用锁管理
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
条件变量
(C++11)
信号量
闩锁和屏障
(C++20)
(C++20)
期物
(C++11)
(C++11)
(C++11)
(C++11)
安全回收
(C++26)
危害指针
原子类型
(C++11)
(C++20)
原子类型的初始化
(C++11)(在 C++20 中弃用)
(C++11)(在 C++20 中弃用)
内存顺序
(C++11)(在 C++26 中弃用)
原子操作的自由函数
原子标志的自由函数
 
 
std::future<R> get_future();
(since C++11)

返回与 *this 共享相同状态的 future 对象。

如果 *this 没有共享状态或已调用 get_future,则会抛出异常。要获取 promise-future 通信通道的多个“pop”端,请使用 std::future::share

对此函数的调用不会与对 set_valueset_exceptionset_value_at_thread_exitset_exception_at_thread_exit 的调用引入数据竞争(因此它们无需相互同步)。

[编辑] 参数

(无)

[编辑] 返回值

指向 *this 的共享状态的 future。

[编辑] 异常

std::future_error 在以下情况下:

  • *this 没有共享状态。错误代码设置为 no_state
  • 已在与 *this 具有相同共享状态的 promise 上调用了 get_future()。错误代码设置为 future_already_retrieved