|c unique lock||1.48||0.8||3825||81|
A unique lock is an object that manages a mutex object with unique ownership in both states: locked and unlocked. On construction (or by move-assigning to it), the object acquires a mutex object, for whose locking and unlocking operations becomes responsible. The object supports both states: locked and unlocked.What is unique lock in C++ 11?
Unique lock is a class that is available form C++ 11. Unique lock is a wrapper over a mutex. It will own the mutex that is passed to unique lock. 1. A unique lock can have different locking strategies. 2. Time based locking are available [try_lock_for, try_lock_until]. 3. Recursive locking is also available. 4.How does the unique_lock destructer work?
When the unique_lock is constructed it will lock the mutex, and it gets destructed it will unlock the mutex. More importantly: If a exceptions is thrown, the std::unique_lock destructer will be called and so the mutex will be unlocked.Is it possible to lock a mutex with a unique_lock?
@chmike: Theoretically yes. However Mutices are not exactly lightweight constructs, so the additional overhead of the unique_lock is likely to be dwarfed by the cost of actually locking and unlocking the mutex (if the compiler didn't optimize that overhead away, which could be possible).