Lockable
, TimedLockable
, Lockable
的基础上加上了timeoutSharedLockable
, TimedLockable
基础上,允许shared ownership(同时也支持exclusive)UpgradeLockable
, SharedLockable
基础上,允许upgradable ownership(同时也支持shared、exclusive)SharedLockable
concept: unlock()
, just as if it had been acquired by a call to lock()
.lock_guard
Lockable
objectunique_lock
lock_guard
复杂在:不仅提供RAII-style的lock,还允许用户指定是否在ctor中立即lock,意味着可以指定推迟lock(defer acquiring the lock,通过指定defer_lock_t参数),直到显式调用其lock()方法TimedLockable
concept,前提是需要lock的Lockable object本身支持boost::unique_lock
are not thread-safe...[注:这句没看懂。。。]shared_lock
upgrade_lock
upgrade_to_unique_lock
mutex
boost::mutex
实现了Lockable
concept,提供exclusive-ownership mutex. boost::mutex
at any time. lock()
, try_lock()
and unlock()
shall be permitted.try_mutex
timed_mutex
recursive_mutex
recursive_try_mutex
recursive_timed_mutex
shared_mutex
wait
on an instance of condition_variable
or condition_variable_any
. When the thread is woken from the wait, then it checks to see if the appropriate condition is now true, and continues if so. If the condition is not true, then the thread then calls wait
again to resume waiting.(中文参考)lock
is passed to wait()
; wait()
will atomically add the thread to the set of threads waiting on the condition variable, and unlock the mutex. When the thread is woken, the mutex will be locked again before the call to wait
returns. This allows other threads to acquire the mutex in order to update the shared data, and ensures that the data associated with the condition is correctly synchronized.In the mean time, another thread sets the condition to true
, and then calls either notify_one()
or notify_all()
on the condition variable to wake one waiting thread or all the waiting threads respectively.
boost::unique_lock<boost::mutex>类型;
condition_variable一般更优化
文章评论(0条评论)
登录后参与讨论