[thread.lock.unique.general]

# 32 Concurrency support library [[thread]](./#thread)

## 32.6 Mutual exclusion [[thread.mutex]](thread.mutex#thread.lock.unique.general)

### 32.6.5 Locks [[thread.lock]](thread.lock#unique.general)

#### 32.6.5.4 Class template unique_lock [[thread.lock.unique]](thread.lock.unique#general)

#### 32.6.5.4.1 General [thread.lock.unique.general]

[ð](#lib:unique_lock)

namespace std {template<class Mutex>class unique_lock {public:using mutex_type = Mutex; // [[thread.lock.unique.cons]](thread.lock.unique.cons "32.6.5.4.2 Constructors, destructor, and assignment"), construct/copy/destroy unique_lock() noexcept; explicit unique_lock(mutex_type& m);
 unique_lock(mutex_type& m, defer_lock_t) noexcept;
 unique_lock(mutex_type& m, try_to_lock_t);
 unique_lock(mutex_type& m, adopt_lock_t); template<class Clock, class Duration> unique_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time); template<class Rep, class Period> unique_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time); ~unique_lock();

 unique_lock(const unique_lock&) = delete;
 unique_lock& operator=(const unique_lock&) = delete;

 unique_lock(unique_lock&& u) noexcept;
 unique_lock& operator=(unique_lock&& u) noexcept; // [[thread.lock.unique.locking]](thread.lock.unique.locking "32.6.5.4.3 Locking"), lockingvoid lock(); bool try_lock(); template<class Rep, class Period>bool try_lock_for(const chrono::duration<Rep, Period>& rel_time); template<class Clock, class Duration>bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time); void unlock(); // [[thread.lock.unique.mod]](thread.lock.unique.mod "32.6.5.4.4 Modifiers"), modifiersvoid swap(unique_lock& u) noexcept;
 mutex_type* release() noexcept; // [[thread.lock.unique.obs]](thread.lock.unique.obs "32.6.5.4.5 Observers"), observersbool owns_lock() const noexcept; explicit operator bool() const noexcept;
 mutex_type* mutex() const noexcept; private: mutex_type* pm; // *exposition only*bool owns; // *exposition only*};}

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L8399)

An object of type unique_lock controls the ownership of a lockable
object within a scope[.](#1.sentence-1)

Ownership of the lockable object may be acquired at
construction or after construction, and may be transferred, after
acquisition, to another unique_lock object[.](#1.sentence-2)

Objects of type unique_lock are not
copyable but are movable[.](#1.sentence-3)

The behavior of a program is undefined if the contained pointerpm is not null and the lockable object pointed
to by pm does not exist for the entire remaining
lifetime ([[basic.life]](basic.life "6.8.4 Lifetime")) of the unique_lock object[.](#1.sentence-4)

The suppliedMutex type shall meet the [*Cpp17BasicLockable*](thread.req.lockable.basic#:Cpp17BasicLockable "32.2.5.2 Cpp17BasicLockable requirements [thread.req.lockable.basic]") requirements ([[thread.req.lockable.basic]](thread.req.lockable.basic "32.2.5.2 Cpp17BasicLockable requirements"))[.](#1.sentence-5)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L8411)

[*Note [1](#note-1)*:

unique_lock<Mutex> meets the [*Cpp17BasicLockable*](thread.req.lockable.basic#:Cpp17BasicLockable "32.2.5.2 Cpp17BasicLockable requirements [thread.req.lockable.basic]") requirements[.](#2.sentence-1)

If Mutex meets the [*Cpp17Lockable*](thread.req.lockable.req#:Cpp17Lockable "32.2.5.3 Cpp17Lockable requirements [thread.req.lockable.req]") requirements ([[thread.req.lockable.req]](thread.req.lockable.req "32.2.5.3 Cpp17Lockable requirements")),unique_lock<Mutex> also meets the [*Cpp17Lockable*](thread.req.lockable.req#:Cpp17Lockable "32.2.5.3 Cpp17Lockable requirements [thread.req.lockable.req]") requirements;
if Mutex meets the [*Cpp17TimedLockable*](thread.req.lockable.timed#:Cpp17TimedLockable "32.2.5.4 Cpp17TimedLockable requirements [thread.req.lockable.timed]") requirements ([[thread.req.lockable.timed]](thread.req.lockable.timed "32.2.5.4 Cpp17TimedLockable requirements")),unique_lock<Mutex> also meets the [*Cpp17TimedLockable*](thread.req.lockable.timed#:Cpp17TimedLockable "32.2.5.4 Cpp17TimedLockable requirements [thread.req.lockable.timed]") requirements[.](#2.sentence-2)

â *end note*]
