#include #include #include #include #include #include #include #include using namespace std ; int calculate_value() { cout << "Calculating value in background...\n"; this_thread::sleep_for(chrono::seconds(20)); // Simulate long computation return 42; } int main() { future future_result = async(launch::deferred, calculate_value); cout << "Main thread continues to execute. Waits for 10 seconds\n"; this_thread::sleep_for(chrono::seconds(10)); cout << "Waiting for result...\n"; int result = future_result.get(); // Blocks until the result is available cout << "Result is: " << result << endl; return 0; }