3
在VS2015中的下面的代码中,我在第一行得到acefbd
,这是正确的。但是在第二次测试中,我将其分为单独的行,输出为abcdef
。VS2015 std ::异步奇怪
这是预期的行为?
#include <future>
#include <iostream>
using namespace std;
void a() {
std::cout << "a";
std::this_thread::sleep_for (std::chrono::seconds (3));
std::cout << "b";
}
void c() {
std::cout << "c";
std::this_thread::sleep_for (std::chrono::seconds (4));
std::cout << "d";
}
void e() {
std::cout << "e";
std::this_thread::sleep_for (std::chrono::seconds (2));
std::cout << "f";
}
int main()
{
std::async (std::launch::async, a), std::async (std::launch::async, c), std::async (std::launch::async, e);
cout << "\n2nd Test" << endl;
std::async (std::launch::async, a);
std::async (std::launch::async, c);
std::async (std::launch::async, e);
}
你知道以何种顺序临时工被破坏?像是它的实现定义? – Rakete1111
@ Rakete1111我假设你的意思是使用逗号表达式进行第一次测试?然后不,我不知道,也不是没有看过规范。 –
@ Rakete1111临时对象在同一个完整表达式中以相反的构造顺序被破坏;除了由于被绑定到引用而延长了生命周期的那些。 (哪些不这样做)。 –