boost::condition::timed_wait 的使用示例

2024-04-05

有人有如何最轻松地使用 boost::condition::timed_wait 的示例吗?有一些关于该主题的主题here https://stackoverflow.com/questions/2259025/how-do-i-get-boostconditiontimed-wait-to-compile, here https://stackoverflow.com/questions/4669995/what-does-boostcondition-variabletimed-wait-return-on-spurious-wakeups and here https://stackoverflow.com/questions/6877032/boostcondition-variable-timed-wait-return-immediately,但没有一个提供有效的示例。和往常一样,Boost 文档非常稀疏。


实际上,我终于找到了带有完整示例的链接here http://www.justsoftwaresolutions.co.uk/threading/condition-variable-spurious-wakes.html。经过一些适应,这似乎就是我们的召唤。

boost::system_time const timeout=boost::get_system_time()+ boost::posix_time::milliseconds(35000);
boost::mutex::scoped_lock lock(the_mutex);
if(the_condition_variable.timed_wait(lock,timeout,&CondFulfilled))
{
    <cond fulfilled code>
}
else
{
    <timeout code>
}
bool CondFulfilled() { ... }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

boost::condition::timed_wait 的使用示例 的相关文章

随机推荐