Usage of boost::unique_lock::timed_lock

后端 未结 2 1137
感情败类
感情败类 2021-01-21 17:44

boost::timed_lock

void wait(int seconds) 
{ 
  boost::this_thread::sleep(boost::posix_time::seconds(seconds)); 
} 

boost::timed_mutex mutex; 

void thread() 
{          


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-21 18:14

    You are right. The example doesn't properly handle the state of when the mutex fails to lock. If you read closely just below that example you'll see this quoted there:

    The above example uses various methods to illustrate some of the features provided by boost::unique_lock. Certainly, the usage of these features does not necessarily make sense for the given scenario; the usage of boost::lock_guard in the previous example was already adequate. This example is rather meant to demonstrate the possibilities offered by boost::unique_lock.

提交回复
热议问题