/* This program demonstrates a simple usage of futures. * The main program creates (via the async() call) two threads that do some computation. * Then, the main thread waits for their results, adds them together and prints the result. */ #include #include #include #include #include #include #include #include #include std::future produce(int a, int b) { return std::async(std::launch::async, [a,b]() {return a+b; }); } int main(int argc, char** argv) { std::future f1 = produce(10, 15); std::future f2 = produce(15, 20); int r = f1.get() + f2.get(); printf("Result=%d\n", r); }