#include <iostream>
#include <thread>
#include <future>
// https://en.cppreference.com/w/cpp/thread/promise
// https://zh.cppreference.com/w/cpp/thread/promise
void add(std::promise<int> accumulate_promise, int x, int y)
{
int sum = x + y;
accumulate_promise.set_value(sum); // Notify future
}
int main()
{
std::promise<int> add_promise;
std::future<int> add_future = add_promise.get_future();
std::thread work_thread(add, std::move(add_promise), 100, 200);
add_future.wait(); // wait for result
std::cout << "result=" << add_future.get() << '\n';
work_thread.join(); // wait for thread completion
std::cout << "End!\n";
}