简体   繁体   English

std::condition_variable 是第一次检查条件,还是必须等待某人发出通知?

[英]std::condition_variable checks the condition for the first time, or do you have to wait for someone to make a notify?

std::condition_variable checks the condition for the first time, or do you have to wait for someone to make a notify? std::condition_variable 是第一次检查条件,还是必须等待某人发出通知?

This is answered by reading documentation .这可以通过阅读文档来回答。

It's like:就像是:

while (!pred()) {
    wait(lock);
}

So, the condition is checked first .因此,首先检查条件。

This can also be shown by testing it (though, to be fair, it's hard to know just from that whether the results are deterministic).这也可以通过测试来证明(不过,公平地说,很难从中知道结果是否是确定性的)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM