Files
cppdraft_translate/cppdraft/thread/lock/unique/locking.md
2025-10-25 03:02:53 +03:00

7.6 KiB

[thread.lock.unique.locking]

32 Concurrency support library [thread]

32.6 Mutual exclusion [thread.mutex]

32.6.5 Locks [thread.lock]

32.6.5.4 Class template unique_lock [thread.lock.unique]

32.6.5.4.3 Locking [thread.lock.unique.locking]

🔗

void lock();

1

#

Effects: As if by pm->lock().

2

#

Postconditions: owns == true.

3

#

Throws: Any exception thrown by pm->lock().

system_error when an exception is required ([thread.req.exception]).

4

#

Error conditions:

  • (4.1)

    operation_not_permitted — if pm is nullptr.

  • (4.2)

    resource_deadlock_would_occur — if on entry owns is true.

🔗

bool try_lock();

5

#

Preconditions: The supplied Mutex meets the Cpp17Lockable requirements ([thread.req.lockable.req]).

6

#

Effects: As if by pm->try_lock().

7

#

Postconditions: owns == res, where res is the value returned bypm->try_lock().

8

#

Returns: The value returned by pm->try_lock().

9

#

Throws: Any exception thrown by pm->try_lock().

system_error when an exception is required ([thread.req.exception]).

10

#

Error conditions:

  • (10.1)

    operation_not_permitted — if pm is nullptr.

  • (10.2)

    resource_deadlock_would_occur — if on entry owns is true.

🔗

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

11

#

Preconditions: The supplied Mutex type meets the Cpp17TimedLockable requirements ([thread.req.lockable.timed]).

12

#

Effects: As if by pm->try_lock_until(abs_time).

13

#

Postconditions: owns == res, where res is the value returned bypm->try_lock_until(abs_time).

14

#

Returns: The value returned by pm->try_lock_until(abs_time).

15

#

Throws: Any exception thrown by pm->try_lock_until(abstime).

system_error when an exception is required ([thread.req.exception]).

16

#

Error conditions:

  • (16.1)

    operation_not_permitted — if pm is nullptr.

  • (16.2)

    resource_deadlock_would_occur — if on entry owns istrue.

🔗

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

17

#

Preconditions: The supplied Mutex type meets the Cpp17TimedLockable requirements ([thread.req.lockable.timed]).

18

#

Effects: As if by pm->try_lock_for(rel_time).

19

#

Postconditions: owns == res, where res is the value returned by pm->try_lock_for(rel_time).

20

#

Returns: The value returned by pm->try_lock_for(rel_time).

21

#

Throws: Any exception thrown by pm->try_lock_for(rel_time).

system_error when an exception is required ([thread.req.exception]).

22

#

Error conditions:

  • (22.1)

    operation_not_permitted — if pm is nullptr.

  • (22.2)

    resource_deadlock_would_occur — if on entry owns istrue.

🔗

void unlock();

23

#

Effects: As if by pm->unlock().

24

#

Postconditions: owns == false.

25

#

Throws: system_error when an exception is required ([thread.req.exception]).

26

#

Error conditions:

operation_not_permitted — if on entry owns is false.