32 Thread support library [thread]

32.5 Mutual exclusion [thread.mutex]

32.5.5 Locks [thread.lock]

32.5.5.4 Class template unique_­lock [thread.lock.unique]

32.5.5.4.3 Locking [thread.lock.unique.locking]

void lock();
Effects: As if by pm->lock().
Postconditions: owns == true.
Throws: Any exception thrown by pm->lock().
system_­error when an exception is required ([thread.req.exception]).
Error conditions:
  • operation_­not_­permitted — if pm is nullptr.
  • resource_­deadlock_­would_­occur — if on entry owns is true.
bool try_lock();
Preconditions: The supplied Mutex meets the Cpp17Lockable requirements ([thread.req.lockable.req]).
Effects: As if by pm->try_­lock().
Postconditions: owns == res, where res is the value returned by the call to try_­lock().
Returns: The value returned by the call to try_­lock().
Throws: Any exception thrown by pm->try_­lock().
system_­error when an exception is required ([thread.req.exception]).
Error conditions:
  • operation_­not_­permitted — if pm is nullptr.
  • 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);
Preconditions: The supplied Mutex type meets the Cpp17TimedLockable requirements ([thread.req.lockable.timed]).
Effects: As if by pm->try_­lock_­until(abs_­time).
Postconditions: owns == res, where res is the value returned by the call to try_­lock_­until(abs_­time).
Returns: The value returned by the call to try_­lock_­until(abs_­time).
Throws: Any exception thrown by pm->try_­lock_­until().
system_­error when an exception is required ([thread.req.exception]).
Error conditions:
  • operation_­not_­permitted — if pm is nullptr.
  • resource_­deadlock_­would_­occur — if on entry owns is true.
template<class Rep, class Period> bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
Preconditions: The supplied Mutex type meets the Cpp17TimedLockable requirements ([thread.req.lockable.timed]).
Effects: As if by pm->try_­lock_­for(rel_­time).
Postconditions: owns == res, where res is the value returned by the call to try_­lock_­for(rel_­time).
Returns: The value returned by the call to try_­lock_­for(rel_­time).
Throws: Any exception thrown by pm->try_­lock_­for().
system_­error when an exception is required ([thread.req.exception]).
Error conditions:
  • operation_­not_­permitted — if pm is nullptr.
  • resource_­deadlock_­would_­occur — if on entry owns is true.
void unlock();
Effects: As if by pm->unlock().
Postconditions: owns == false.
Throws: system_­error when an exception is required ([thread.req.exception]).
Error conditions:
  • operation_­not_­permitted — if on entry owns is false.