是什么赋予了std :: future一些共享状态 [英] What gives a std::future some shared state

查看:70
本文介绍了是什么赋予了std :: future一些共享状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

std::future get wait

A std::future has a std::future::valid method, which indicates whether the future object refers to some shared state. None of the constructors construct a future object that refers to shared state (except the move constructor, which can move the shared state from one future object to another). All the methods of the class (get, wait, wait_for and wait_until require the future object to have shared state as a precondition (they have undefined behaviour if valid() == false). How then can a std::future acquire some shared state and become useful?

推荐答案

通常,您通常不单独使用std::future.您可以将其与 std::promise 一起使用. std::promise 构造函数设置了一些共享状态.然后,您可以使用 std::promise::get_future() 方法来获取表示该共享状态.

You do not normally use a std::future in isolation; you use it with a std::promise. The std::promise constructors set up some shared state. You can then use the std::promise::get_future() method to get a std::future that refers to that shared state.

这篇关于是什么赋予了std :: future一些共享状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆