Puzzle 15 | Back from the Future |
| #include <future> |
| #include <iostream> |
| |
| int main() |
| { |
| char counter = 0; |
| |
| auto future1 = std::async(std::launch::async, [&]() |
| { |
| counter++; |
| }); |
| auto future2 = std::async(std::launch::async, [&]() |
| { |
| return counter; |
| }); |
| |
| future1.wait(); |
| |
| // Cast to int to print it as a numerical value rather than a character |
| std::cout << (int)future2.get(); |
| } |
Guess the Output | |
---|---|
Try to guess what the output is before moving to the next page. |
The program has undefined ...
Get C++ Brain Teasers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.