在 VS2015 的以下代码中,我进入acefbd
了第一行,这是正确的。但在第二次测试中,我将其分成单独的行,输出为abcdef
.
这是预期的行为吗?
#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);
}