我對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