[thread.lock.unique.locking]

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

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

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

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

#### 32.6.5.4.3 Locking [thread.lock.unique.locking]

[ð](#lib:lock,unique_lock)

`void lock();
`

[1](#1)

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

*Effects*: As if by pm->lock()[.](#1.sentence-1)

[2](#2)

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

*Postconditions*: owns == true[.](#2.sentence-1)

[3](#3)

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

*Throws*: Any exception thrown by pm->lock()[.](#3.sentence-1)

system_error when an exception
is required ([[thread.req.exception]](thread.req.exception "32.2.2 Exceptions"))[.](#3.sentence-2)

[4](#4)

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

*Error conditions*: 

- [(4.1)](#4.1)

  operation_not_permitted â if pm is nullptr[.](#4.1.sentence-1)

- [(4.2)](#4.2)

  resource_deadlock_would_occur â if on entry owns is true[.](#4.2.sentence-1)

[ð](#lib:try_lock,unique_lock)

`bool try_lock();
`

[5](#5)

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

*Preconditions*: The supplied 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"))[.](#5.sentence-1)

[6](#6)

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

*Effects*: As if by pm->try_lock()[.](#6.sentence-1)

[7](#7)

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

*Postconditions*: owns == res, where res is the value returned bypm->try_lock()[.](#7.sentence-1)

[8](#8)

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

*Returns*: The value returned by pm->try_lock()[.](#8.sentence-1)

[9](#9)

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

*Throws*: Any exception thrown by pm->try_lock()[.](#9.sentence-1)

system_error when an exception
is required ([[thread.req.exception]](thread.req.exception "32.2.2 Exceptions"))[.](#9.sentence-2)

[10](#10)

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

*Error conditions*: 

- [(10.1)](#10.1)

  operation_not_permitted â if pm is nullptr[.](#10.1.sentence-1)

- [(10.2)](#10.2)

  resource_deadlock_would_occur â if on entry owns is true[.](#10.2.sentence-1)

[ð](#lib:try_lock_until,unique_lock)

`template<class Clock, class Duration>
  bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
`

[11](#11)

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

*Preconditions*: The supplied Mutex type 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"))[.](#11.sentence-1)

[12](#12)

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

*Effects*: As if by pm->try_lock_until(abs_time)[.](#12.sentence-1)

[13](#13)

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

*Postconditions*: owns == res, where res is the value returned bypm->try_lock_until(abs_time)[.](#13.sentence-1)

[14](#14)

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

*Returns*: The value returned by pm->try_lock_until(abs_time)[.](#14.sentence-1)

[15](#15)

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

*Throws*: Any exception thrown by pm->try_lock_until(abstime)[.](#15.sentence-1)

system_error when an
exception is required ([[thread.req.exception]](thread.req.exception "32.2.2 Exceptions"))[.](#15.sentence-2)

[16](#16)

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

*Error conditions*: 

- [(16.1)](#16.1)

  operation_not_permitted â if pm is nullptr[.](#16.1.sentence-1)

- [(16.2)](#16.2)

  resource_deadlock_would_occur â if on entry owns istrue[.](#16.2.sentence-1)

[ð](#lib:try_lock_for,unique_lock)

`template<class Rep, class Period>
  bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
`

[17](#17)

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

*Preconditions*: The supplied Mutex type 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"))[.](#17.sentence-1)

[18](#18)

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

*Effects*: As if by pm->try_lock_for(rel_time)[.](#18.sentence-1)

[19](#19)

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

*Postconditions*: owns == res, where res is the value returned by pm->try_lock_for(rel_time)[.](#19.sentence-1)

[20](#20)

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

*Returns*: The value returned by pm->try_lock_for(rel_time)[.](#20.sentence-1)

[21](#21)

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

*Throws*: Any exception thrown by pm->try_lock_for(rel_time)[.](#21.sentence-1)

system_error when an
exception is required ([[thread.req.exception]](thread.req.exception "32.2.2 Exceptions"))[.](#21.sentence-2)

[22](#22)

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

*Error conditions*: 

- [(22.1)](#22.1)

  operation_not_permitted â if pm is nullptr[.](#22.1.sentence-1)

- [(22.2)](#22.2)

  resource_deadlock_would_occur â if on entry owns istrue[.](#22.2.sentence-1)

[ð](#lib:unlock,unique_lock)

`void unlock();
`

[23](#23)

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

*Effects*: As if by pm->unlock()[.](#23.sentence-1)

[24](#24)

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

*Postconditions*: owns == false[.](#24.sentence-1)

[25](#25)

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

*Throws*: system_error when
an exception is required ([[thread.req.exception]](thread.req.exception "32.2.2 Exceptions"))[.](#25.sentence-1)

[26](#26)

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

*Error conditions*: 

- [(26.1)](#26.1)

operation_not_permitted â if on entry owns is false[.](#26.sentence-1)
