Files
cppdraft_translate/cppdraft/thread/timedmutex/requirements/general.md
2025-10-25 03:02:53 +03:00

6.0 KiB

[thread.timedmutex.requirements.general]

32 Concurrency support library [thread]

32.6 Mutual exclusion [thread.mutex]

32.6.4 Mutex requirements [thread.mutex.requirements]

32.6.4.3 Timed mutex types [thread.timedmutex.requirements]

32.6.4.3.1 General [thread.timedmutex.requirements.general]

1

#

The timed mutex types are the standard library types timed_mutex,recursive_timed_mutex, and shared_timed_mutex.

They meet the requirements set out below.

In this description, m denotes an object of a mutex type,rel_time denotes an object of an instantiation of duration, and abs_time denotes an object of an instantiation of time_point.

[Note 1:

The timed mutex types meet the Cpp17TimedLockable requirements ([thread.req.lockable.timed]).

— end note]

2

#

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

3

#

Preconditions: If m is of type timed_mutex orshared_timed_mutex, the calling thread does not own the mutex.

4

#

Effects: The function attempts to obtain ownership of the mutex within the relative timeout ([thread.req.timing]) specified by rel_time.

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()).

The function returns within the timeout specified byrel_time only if it has obtained ownership of the mutex object.

[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.

— end note]

5

#

Synchronization: If try_lock_for() returns true, prior unlock() operations on the same object synchronize with ([intro.multithread]) this operation.

6

#

Return type: bool.

7

#

Returns: true if ownership was obtained, otherwise false.

8

#

Throws: Timeout-related exceptions ([thread.req.timing]).

9

#

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

10

#

Preconditions: If m is of type timed_mutex orshared_timed_mutex, the calling thread does not own the mutex.

11

#

Effects: The function attempts to obtain ownership of the mutex.

Ifabs_time has already passed, the function attempts to obtain ownership without blocking (as if by calling try_lock()).

The function returns before the absolute timeout ([thread.req.timing]) specified byabs_time only if it has obtained ownership of the mutex object.

[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.

— end note]

12

#

Synchronization: If try_lock_until() returns true, prior unlock() operations on the same object synchronize with ([intro.multithread]) this operation.

13

#

Return type: bool.

14

#

Returns: true if ownership was obtained, otherwise false.

15

#

Throws: Timeout-related exceptions ([thread.req.timing]).