[thread.lock.shared.locking]

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

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

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

#### 32.6.5.5 Class template shared_lock [[thread.lock.shared]](thread.lock.shared#locking)

#### 32.6.5.5.3 Locking [thread.lock.shared.locking]

[ð](#lib:lock,shared_lock)

`void lock();
`

[1](#1)

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

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

[2](#2)

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

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

[3](#3)

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

*Throws*: Any exception thrown by pm->lock_shared()[.](#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#L9082)

*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 istrue[.](#4.2.sentence-1)

[ð](#lib:try_lock,shared_lock)

`bool try_lock();
`

[5](#5)

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

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

[6](#6)

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

*Postconditions*: owns == res, where res is the value returned by
the call to pm->try_lock_shared()[.](#6.sentence-1)

[7](#7)

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

*Returns*: The value returned by the call to pm->try_lock_shared()[.](#7.sentence-1)

[8](#8)

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

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

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

[9](#9)

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

*Error conditions*: 

- [(9.1)](#9.1)

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

- [(9.2)](#9.2)

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

[ð](#lib:try_lock_until,shared_lock)

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

[10](#10)

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

*Preconditions*: Mutex meets the [*Cpp17SharedTimedLockable*](thread.req.lockable.shared.timed#:Cpp17SharedTimedLockable "32.2.5.6 Cpp17SharedTimedLockable requirements [thread.req.lockable.shared.timed]") requirements ([[thread.req.lockable.shared.timed]](thread.req.lockable.shared.timed "32.2.5.6 Cpp17SharedTimedLockable requirements"))[.](#10.sentence-1)

[11](#11)

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

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

[12](#12)

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

*Postconditions*: owns == res, where res is the value returned by
the call to pm->try_lock_shared_until(abs_time)[.](#12.sentence-1)

[13](#13)

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

*Returns*: The value returned by the call topm->try_lock_shared_until(abs_time)[.](#13.sentence-1)

[14](#14)

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

*Throws*: Any exception thrown by pm->try_lock_shared_until(abs_time)[.](#14.sentence-1)

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

[15](#15)

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

*Error conditions*: 

- [(15.1)](#15.1)

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

- [(15.2)](#15.2)

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

[ð](#lib:try_lock_for,shared_lock)

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

[16](#16)

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

*Preconditions*: Mutex meets the [*Cpp17SharedTimedLockable*](thread.req.lockable.shared.timed#:Cpp17SharedTimedLockable "32.2.5.6 Cpp17SharedTimedLockable requirements [thread.req.lockable.shared.timed]") requirements ([[thread.req.lockable.shared.timed]](thread.req.lockable.shared.timed "32.2.5.6 Cpp17SharedTimedLockable requirements"))[.](#16.sentence-1)

[17](#17)

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

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

[18](#18)

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

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

[19](#19)

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

*Returns*: The value returned by the call to pm->try_lock_shared_for(rel_time)[.](#19.sentence-1)

[20](#20)

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

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

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

[21](#21)

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

*Error conditions*: 

- [(21.1)](#21.1)

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

- [(21.2)](#21.2)

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

[ð](#lib:unlock,shared_lock)

`void unlock();
`

[22](#22)

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

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

[23](#23)

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

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

[24](#24)

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

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

[25](#25)

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

*Error conditions*: 

- [(25.1)](#25.1)

operation_not_permitted â if on entry owns isfalse[.](#25.sentence-1)
