std::async
의 동작에 대한 질문이 std::launch::async
정책 & std::future
async에서 반환되었습니다.std :: async with asp :: launch :: async policy의 동작
다음 코드에서 메인 스레드는 async
호출에 의해 생성 된 스레드에서 foo()
의 완료를 기다립니다.
#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++ 표준을 준수합니까?
- Q2. Q1의 대답이 '예'라면, 그 진술은 무엇이라고 말합니까?
표준에 대해 정말 놀라운 점은 하나의 각주가 챕터를 완전히 변경한다는 것입니다. – orlp