#include <iostream>
#include <string>
#include <thread>
#include <future>
int main()
{
auto pms = std::promise<std::string>();
auto ftr = pms.get_future();
std::thread([&](){pms.set_value("hello world");});
ftr.wait();
std::cout << ftr.get() << std::endl;
return 0;
}
this linkによると、結果は使用可能になるまでブロックされます。
future :: wait()ブロックがなぜ発生しないのですか?
ただし、上記のコードでは何も印刷できません。明らかに、メインスレッドはpms.set_value
のスレッドが終了する前に終了しています。
なぜ、ftr.wait()
ブロックされますか?
私はスレッドを取り外す示唆ないためにはstd ::を見 – LeDYoM