#include <iostream>
#include <string>
#include <thread>
#include <future>
using namespace std;
int run1(std::promise<int> &tmp)
{
int a = 10;
tmp.set_value(a);
std::cout << "子线程ID = " << std::this_thread::get_id() << std::endl;
return 3;
}
int main()
{
std::cout << "主线程ID = " << std::this_thread::get_id() << std::endl;
std::promise<int> tmp;
std::thread obj(run1, std::ref(tmp));
obj.join();
//从线程当中获取一个值,拿到这个值后,可以传递到另一个线程当中。
std::future<int> a = tmp.get_future();//将std::promise和std::future进行绑定
std::cout << a.get() << std::endl;
return 0;
}