shared_futures
でこれを行うことができるかどうかを知りたいと思っていました。 本質的に私は約束を参照する2つのスレッドを持っています。 スレッドのいずれかが、その出力を処理し、残りのスレッドからの別の割り当てをリッスンすることに戻すことを望みます。このようなことをすることはできますか?get future with get
void tA(std::promise<string>& p)
{
....
std::string r = "Hello from thread A";
p.set_value(std::move(r));
}
void tB(std::promise<string>& p)
{
...
std::string r = "Hello from thread A";
p.set_value(std::move(r));
}
int main() {
std::promise<std::string> inputpromise;
std::shared_future<std::string> inputfuture(inputpromise.get_future());
//start the thread A
std::thread t(std::bind(&tA,std::ref(inputpromise));
//start the thread B
std::thread t(std::bind(&tA,std::ref(inputpromise));
std::future<std::string> f(p.get_future());
std::string response = f.get(); ------> Will this unblock when one thread sets a value to the promise and can i go back listening for more assignments on the promise ?
if(response=="b")
response = f.get(); -->listen for the assignment from the remaining thread
}