有人有如何最轻松地使用 boost::condition::timed_wait 的示例吗?该主题有一些线程here , here和 here ,但没有一个具有工作示例。而且 boost doc 像往常一样非常稀疏。
最佳答案
实际上,我终于找到了一个完整示例的链接here .稍微适应一下,这似乎是电话。
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() { ... }
关于c++ - boost::condition::timed_wait 的使用示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7078511/