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