c++11スレッド戻り値の取得
768 ワード
#include //std::cout std::endl
#include //std::thread
#include //std::future std::promise
#include //std::ref
#include //std::chrono::seconds
void initiazer(std::promise &promiseObj) {
std::cout << "Inside thread: " << std::this_thread::get_id() << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
promiseObj.set_value(35);
}
int main() {
std::promise promiseObj;
std::future futureObj = promiseObj.get_future();
std::thread th(initiazer, std::ref(promiseObj));
std::cout << futureObj.get() << std::endl;
th.join();
return 0;
}