std::lunique_lock

From Cppreference

Jump to: navigation, search
Defined in header <mutex>

template<typename Mutex>
class unique_lock;
(C++11 feature)

The class unique_lock implements general-purpose mutex ownership wrapper allowing deferred locking, timed locking, recursive locking, transfer of lock ownership, and use with condition variables. The class is non-copyable but movable.

Contents

[edit] Member types

Member type Definition
mutex_type Mutex

[edit] Member functions

(constructor)
Constructs a unique_lock, optionally locking the supplied mutex
(public member function)
(destructor)
Unlocks the supplied mutex, if owned
(public member function)
operator=
Unlocks the mutex, if owned, and acquires ownership of another
(public member function)
lock
Locks the supplied mutex
(public member function)
try_lock
Attempts to lock the supplied mutex
(public member function)
try_lock_for
Attempts to lock the supplied TimedLockable mutex for specified std::duration
(public member function)
try_lock_until
Attempts to lock the supplied TimedLockable mutex until specified std::time_point
(public member function)
unlock
Unlocks the supplied mutex
(public member function)
swap
Swaps state with another std::unique_lock
(public member function)
mutex
Returns a pointer to the supplied mutex
(public member function)
release
Unlocks the mutex and returns a pointer to the mutex object
(public member function)
owns_lock
Tests if this unique_lock owns its mutex
(public member function)
operator bool()
Tests if this unique_lock owns its mutex
(public member function)

[edit] Helper classes

defer_lock_t
tag type used to disambiguate unique_lock constructors
(class)
try_to_lock_t
tag type used to disambiguate unique_lock constructors
(class)
adopt_lock_t
tag type used to disambiguate unique_lock constructors
(class)

[edit] Non-member constants

defer_lock
tag constant used to disambiguate unique_lock constructors
(constant)
try_to_lock
tag constant used to disambiguate unique_lock constructors
(constant)
adopt_lock
tag constant used to disambiguate unique_lock constructors
(constant)

[edit] Non-member functions

std_swap
Specialization of std::swap for unique_locks
(function template)

[edit] Example