我对std::async
功能的行为与std::launch::async
政策从异步返回& std::future
对象的一些问题。性病的行为::异步用的std ::推出::异步政策
在以下代码中,主线程等待完成foo()
对async
创建的线程的调用。
#include <thread>
#include <future>
#include <iostream>
void foo()
{
std::cout << "foo:begin" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(10));
std::cout << "foo:done" << std::endl;
}
int main()
{
std::cout << "main:begin" << std::endl;
{
auto f = std::async(std::launch::async, foo);
// dtor f::~f blocks until completion of foo()... why??
}
std::this_thread::sleep_for(std::chrono::seconds(2));
std::cout << "main:done" << std::endl;
}
而且我知道http://www.stdthread.co.uk/doc/headers/future/async.html说
与返回性病的 异步状态相关联的最后一个未来对象的析构函数::未来应阻止,直到 未来做好准备。
我的问题是:
- Q1。这种行为是否符合当前的C++标准?第二季度销售价格为
- 。如果Q1的答案是肯定的,哪些陈述说?
这个标准的惊人之处在于,经常一个脚注完全改变了一个章节...... – orlp 2012-03-16 07:39:07