[英]Does std::promise internally use std::condition_variable to notify the associated std::future?
My question is does std::promise
notify the associated std::future
through using a std::condition_variable
? 我的问题是
std::promise
通过使用std::condition_variable
来通知关联的std::future
吗?
I search the source code of std::promise
and found this website . 我搜索
std::promise
的源代码并找到了这个网站 。 But I didn't see std::promise
has std::condition_variable
in its member data. 但我没有看到
std::promise
在其成员数据中有std::condition_variable
。
Here's an answer for libc++. 这是libc ++的答案。
A search for condition_variable
in <future>
returned exactly one result: 在
<future>
搜索condition_variable
返回一个结果:
// lines 531 -- 538
class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE __assoc_sub_state
: public __shared_count
{
protected:
exception_ptr __exception_;
mutable mutex __mut_;
mutable condition_variable __cv_;
unsigned __state_;
Here __assoc_sub_state
is introduced. 这里引入了
__assoc_sub_state
。 It is the base class for __assoc_state
: 它是
__assoc_state
的基类:
// lines 617 -- 619
template <class _Rp>
class _LIBCPP_AVAILABILITY_FUTURE __assoc_state
: public __assoc_sub_state
And finally, __assoc_state<_Rp>*
is both a member of future<_Rp>
: 最后,
__assoc_state<_Rp>*
都是future<_Rp>
的成员:
// lines 1082 -- 1085
template <class _Rp>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE future
{
__assoc_state<_Rp>* __state_;
and a member of promise<_Rp>
: 和
promise<_Rp>
的成员:
// lines 1360 -- 1363
template <class _Rp>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE promise
{
__assoc_state<_Rp>* __state_;
So yeah, libc++ std::promise
internally uses a std::condition_variable
to notify the associated std::future
. 所以是的,libc ++
std::promise
内部使用std::condition_variable
来通知关联的std::future
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.