简体   繁体   中英

Usage example of boost::condition::timed_wait

Does someone have an example of how to most easily use boost::condition::timed_wait? There are some threads on the topic here , here and here , but none feature a working example. And boost doc is as usual quite sparse.

Actually, I finally found a link with full example here . With a bit of adapting, this seems to be the call.

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() { ... }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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