线程之间的信号可以通过std :: promise / future或旧的条件变量来实现,有些人可以提供示例/用例,其中1是比其他更好的选择吗?
我知道CV可以用来在线程之间多次发出信号,你能举例说明std :: future / promise多次发出信号吗?
std :: future :: wait_for在性能上与std :: condition_variable :: wait相当吗? 让我们说我需要等待队列中的多个期货作为消费者,是否有理由通过它们并检查它们是否已准备就绪,如下所示?
for(auto it = activeFutures.begin(); it!= activeFutures.end();) {
if(it->valid() && it->wait_for(std::chrono::milliseconds(1)) == std::future_status::ready) {
Printer::print(std::string("+++ Value " + std::to_string(it->get()->getBalance())));
activeFutures.erase(it);
} else {
++it;
}
}