TimedMutex
The TimedMutex concept extends the TimedLockable concept to include inter-thread synchronization.
Requirements
TimedLockableMutex
Additionally, for object m of TimedMutex type.
- The expression
m.try_lock_for(duration)has the following properties- Behaves as an atomic operation.
- Attempts to obtain exclusive ownership of the mutex within the duration specified by
duration. Ifdurationis less or equalduration.zero(), attempts to obtain the ownership without locking (as if bytry_lock()). Otherwise, this function blocks until the mutex is acquired or until the time specified bydurationpasses. It returns withindurationonly if it succeeds, but it allowed to fail to acquire the mutex even if at some point in time duringdurationit was not owned by another thread. In any case, it returnstrueif the mutex was acquired andfalseotherwise. - If
try_lock_for(duration)succeeds, priorunlock()operations on the same object synchronize-with this operation (equivalent to release-acquirestd::memory_order). - The behavior is undefined if the calling thread already owns the mutex (except if m is
std::recursive_timed_mutex)
- The expression
m.try_lock_until(time_point)has the following properties- Behaves as an atomic operation.
- Attempts to obtain exclusive ownership of the mutex within the time left until
time_point. Iftime_pointalready passed, attempts to obtain the ownership without locking (as if bytry_lock()). Otherwise, this function blocks until the mutex is acquired or until the time specified bytime_pointpasses. It returns beforetime_pointonly if it succeeds, but it allowed to fail to acquire the mutex even if at some point in time beforetime_pointit was not owned by another thread. In any case, it returnstrueif the mutex was acquired andfalseotherwise. - If
try_lock_until(time_point)succeeds, priorunlock()operations on the same object synchronize-with this operation (equivalent to release-acquirestd::memory_order). - The behavior is undefined if the calling thread already owns the mutex (except if m is
std::recursive_timed_mutex)
Library types
The following standard library types satisfy TimedMutex:
std::timed_mutexstd::recursive_timed_mutexstd::shared_timed_mutex
See also
- Thread support library
TimedLockableMutex
© cppreference.comLicensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

