In the below code in VS2015, I'm getting acefbd
in the first line, which is correct. but in the 2nd test where I seperate out into individual lines, the output is abcdef
.
Is that intended behavior?
#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);
}