std::unique_lock<Mutex>::unique_lock (3) - Linux Manuals
std::unique_lock<Mutex>::unique_lock: std::unique_lock<Mutex>::unique_lock
NAME
std::unique_lock<Mutex>::unique_lock - std::unique_lock<Mutex>::unique_lock
Synopsis
unique_lock() noexcept; (1) (since C++11)
unique_lock( unique_lock&& other ) noexcept; (2) (since C++11)
explicit unique_lock( mutex_type& m ); (3) (since C++11)
unique_lock( mutex_type& m, std::defer_lock_t t ) noexcept; (4) (since C++11)
unique_lock( mutex_type& m, std::try_to_lock_t t ); (5) (since C++11)
unique_lock( mutex_type& m, std::adopt_lock_t t ); (6) (since C++11)
template< class Rep, class Period >
unique_lock( mutex_type& m, (7) (since C++11)
const std::chrono::duration<Rep,Period>& timeout_duration );
template< class Clock, class Duration >
unique_lock( mutex_type& m, (8) (since C++11)
const std::chrono::time_point<Clock,Duration>& timeout_time );
Constructs a unique_lock, optionally locking the supplied mutex.
1) Constructs a unique_lock with no associated mutex.
2) Move constructor. Initializes the unique_lock with the contents of other. Leaves other with no associated mutex.
3-8) Constructs a unique_lock with m as the associated mutex. Additionally:
3) Locks the associated mutex by calling m.lock(). The behavior is undefined if the current thread already owns the mutex except when the mutex is recursive.
4) Does not lock the associated mutex.
5) Tries to lock the associated mutex without blocking by calling m.try_lock(). The behavior is undefined if the current thread already owns the mutex except when the mutex is recursive.
6) Assumes the calling thread already owns m.
7) Tries to lock the associated mutex by calling m.try_lock_for(timeout_duration). Blocks until specified timeout_duration has elapsed or the lock is acquired, whichever comes first. May block for longer than timeout_duration.
8) Tries to lock the associated mutex by calling m.try_lock_until(timeout_time). Blocks until specified timeout_time has been reached or the lock is acquired, whichever comes first. May block for longer than until timeout_time has been reached.
Parameters
other - another unique_lock to initialize the state with
m - mutex to associate with the lock and optionally acquire ownership of
t - tag parameter used to select constructors with different locking strategies
timeout_duration - maximum duration to block for
timeout_time - maximum time point to block until
Exceptions
Example
// Run this code
Output: