#include <iostream>
#include <thread>
#include <future>
int add(int a, int b) {
return a + b;
}
int main() {
// Step 1: Create a packaged_task with the desired function
std::packaged_task<int(int, int)> task(add);
// Step 2: Get a future associated with the packaged_task
std::future<int> result = task.get_future();
// Step 3: Create a thread and move the packaged_task to it
std::thread worker(std::move(task), 2, 3);
// Step 4: Do other work in the main thread while the worker thread is running
// Step 5: Wait for the worker thread to finish and get the result
int sum = result.get();
// Step 6: Join the worker thread
worker.join();
// Step 7: Print the result
std::cout << "Result: " << sum << std::endl;
return 0;
}