[thread.timedmutex.requirements.general]

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

## 32.6 Mutual exclusion [[thread.mutex]](thread.mutex#thread.timedmutex.requirements.general)

### 32.6.4 Mutex requirements [[thread.mutex.requirements]](thread.mutex.requirements#thread.timedmutex.requirements.general)

#### 32.6.4.3 Timed mutex types [[thread.timedmutex.requirements]](thread.timedmutex.requirements#general)

#### 32.6.4.3.1 General [thread.timedmutex.requirements.general]

[1](#1)

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

The [*timed mutex types*](#def:timed_mutex_types "32.6.4.3.1 General [thread.timedmutex.requirements.general]") are the standard library types timed_mutex,recursive_timed_mutex, and shared_timed_mutex[.](#1.sentence-1)

They
meet the requirements set out below[.](#1.sentence-2)

In this description, m denotes an object of a mutex type,rel_time denotes an object of an
instantiation of [duration](time.duration "30.5 Class template duration [time.duration]"), and abs_time denotes an
object of an
instantiation of [time_point](time.point "30.6 Class template time_­point [time.point]")[.](#1.sentence-3)

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

The timed mutex types meet 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"))[.](#1.sentence-4)

â *end note*]

[2](#2)

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

The expression m.try_lock_for(rel_time) is well-formed
and has the following semantics:

[3](#3)

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

*Preconditions*: If m is of type timed_mutex orshared_timed_mutex, the calling thread does not
own the mutex[.](#3.sentence-1)

[4](#4)

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

*Effects*: The function attempts to obtain ownership of the mutex within the
relative timeout ([[thread.req.timing]](thread.req.timing "32.2.4 Timing specifications"))
specified by rel_time[.](#4.sentence-1)

If the time specified by rel_time is less than or
equal to rel_time.zero(), the function attempts to obtain ownership without blocking (as if by callingtry_lock())[.](#4.sentence-2)

The function returns within the timeout specified byrel_time only if it has obtained ownership of the mutex object[.](#4.sentence-3)

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

As
with try_lock(), there is no guarantee that ownership will be obtained if the
lock is available, but implementations are expected to make a strong effort to do so[.](#4.sentence-4)

â *end note*]

[5](#5)

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

*Synchronization*: If try_lock_for() returns true, prior unlock() operations
on the same object [*synchronize with*](#def:synchronize_with) ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races")) this operation[.](#5.sentence-1)

[6](#6)

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

*Return type*: bool[.](#6.sentence-1)

[7](#7)

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

*Returns*: true if ownership was obtained, otherwise false[.](#7.sentence-1)

[8](#8)

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

*Throws*: Timeout-related exceptions ([[thread.req.timing]](thread.req.timing "32.2.4 Timing specifications"))[.](#8.sentence-1)

[9](#9)

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

The expression m.try_lock_until(abs_time) is well-formed
and has the following semantics:

[10](#10)

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

*Preconditions*: If m is of type timed_mutex orshared_timed_mutex, the calling thread does not own the
mutex[.](#10.sentence-1)

[11](#11)

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

*Effects*: The function attempts to obtain ownership of the mutex[.](#11.sentence-1)

Ifabs_time has already passed, the function attempts to obtain ownership
without blocking (as if by calling try_lock())[.](#11.sentence-2)

The function
returns before the absolute timeout ([[thread.req.timing]](thread.req.timing "32.2.4 Timing specifications")) specified byabs_time only if it has obtained ownership of the mutex object[.](#11.sentence-3)

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

As with try_lock(), there is no guarantee that ownership will
be obtained if the lock is available, but implementations are expected to make a
strong effort to do so[.](#11.sentence-4)

â *end note*]

[12](#12)

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

*Synchronization*: If try_lock_until() returns true, prior unlock() operations on the same object [*synchronize with*](#def:synchronize_with) ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races"))
this operation[.](#12.sentence-1)

[13](#13)

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

*Return type*: bool[.](#13.sentence-1)

[14](#14)

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

*Returns*: true if ownership was obtained, otherwise false[.](#14.sentence-1)

[15](#15)

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

*Throws*: Timeout-related exceptions ([[thread.req.timing]](thread.req.timing "32.2.4 Timing specifications"))[.](#15.sentence-1)
