#include #include #include #include using namespace std; int sum(0); int square(int x) { this_thread::sleep_for(chrono::milliseconds(100)); cout << x << endl; cout << this_thread::get_id() << endl; return x * x; } int main() { vector> av; future a; for (int i = 1; i <= 20; i++) { av.push_back(async(launch::async, &square, i)); } cout << this_thread::get_id() << endl; int v(0); for (auto& avs : av) { v = avs.get(); sum += v; } cout << "The task returned " << sum << endl; return 0; }