Usage example of boost::condition::timed_wait

后端 未结 1 1383
耶瑟儿~
耶瑟儿~ 2021-02-13 05:25

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.

相关标签:
1条回答
  • 2021-02-13 06:04

    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() { ... }
    
    0 讨论(0)
提交回复
热议问题