Pagini recente » Cod sursa (job #1220295) | Cod sursa (job #374830) | Cod sursa (job #2240219) | Cod sursa (job #877208) | Cod sursa (job #2159889)
#include <ctime>
#include <future>
#include <thread>
#include <iostream>
int long_computation(int x, int y)
{
std::this_thread::sleep_for(std::chrono::seconds(5));
return (x + y);
}
int main()
{
auto f = std::async(std::launch::async, long_computation, 42, 1729);
// Do things in the meanwhile...
std::string s;
std::cin >> s;
// And we could continue...
std::cout << f.get(); // Here we join with the asynchronous operation
}