没看源码,前几天用过这些,定时互斥量的作用不一样。他们阻止直到时间结束,然后返回。唯一的锁将阻塞,直到它可以得到锁。
try 锁不会阻塞,然后您可以测试它是否拥有锁的所有权。定时锁将阻塞指定的时间,然后表现为尝试锁 - 即停止阻塞,您可以测试锁的所有权。
我相信在内部,一些不同的 boost 锁是唯一锁的 typedef,因为它们都使用唯一锁。typedef 名称在那里,以便您可以跟踪您使用不同名称的目的,即使您可以使用不同的功能并混淆您的客户端代码。
编辑:这是一个定时锁的例子:
boost::timed_mutex timedMutexObj;
boost::mutex::scoped_lock scopedLockObj(timedMutexObj, boost::get_system_time() + boost::posix_time::seconds(60));
if(scopedLockObj.owns_lock()) {
// proceed
}
供参考: http: //www.boost.org/doc/libs/1_49_0/doc/html/thread/synchronization.html#thread.synchronization.mutex_concepts.timed_lockable.timed_lock
Edit again: to provide a specific answer to your question, yes, it would be wrong to use boost::mutex
as a TimedLockable
because boost::timed_mutex
is provided for this purpose. If they are the same thing in the source and this is undocumented, this is unreliable behavior and you should follow the documentation. (My code example did not used timed_mutex
at first but I updated it)