Przejdź do głównej zawartości

C++ named requirements: TimedMutex (od C++11)

The TimedMutex requirements extend the TimedLockable requirements to include inter-thread synchronization.

Requirements

Additionally, for an 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. If duration is less or equal duration.zero(), attempts to obtain the ownership without blocking (as if by try_lock()). Otherwise, this function blocks until the mutex is acquired or until the time specified by duration passes. It returns within duration only if it succeeds, but it is allowed to fail to acquire the mutex even if at some point in time during duration it was not owned by another thread. In any case, it returns true if the mutex was acquired and false otherwise.
    • If try_lock_for(duration) succeeds, prior unlock() operations on the same object synchronize-with this operation (equivalent to release-acquire std::memory_order).
    • The behavior is undefined if the calling thread already owns the mutex (except if m is std::recursive_timed_mutex).
    • An exception may be thrown by clock, time point, or duration during the execution (clocks, time points, and durations provided by the standard library never throw).
  • 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. If time_point already passed, attempts to obtain the ownership without blocking (as if by try_lock()). Otherwise, this function blocks until the mutex is acquired or until the time specified by time_point passes. It returns before time_point only if it succeeds, but it is allowed to fail to acquire the mutex even if at some point in time before time_point it was not owned by another thread. In any case, it returns true if the mutex was acquired and false otherwise.
    • If try_lock_until(time_point) succeeds, prior unlock() operations on the same object synchronize-with this operation (equivalent to release-acquire std::memory_order).
    • The behavior is undefined if the calling thread already owns the mutex (except if m is std::recursive_timed_mutex).
    • An exception may be thrown by clock, time point, or duration during the execution (clocks, time points, and durations provided by the standard library never throw).

Library types

The following standard library types satisfy TimedMutex:

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DRApplied toBehavior as publishedCorrect behavior
LWG 2093C++11timeout-related exceptions were missing in the specificationmentioned

C++ named requirements: TimedMutex (od C++11)

The TimedMutex requirements extend the TimedLockable requirements to include inter-thread synchronization.

Requirements

Additionally, for an 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. If duration is less or equal duration.zero(), attempts to obtain the ownership without blocking (as if by try_lock()). Otherwise, this function blocks until the mutex is acquired or until the time specified by duration passes. It returns within duration only if it succeeds, but it is allowed to fail to acquire the mutex even if at some point in time during duration it was not owned by another thread. In any case, it returns true if the mutex was acquired and false otherwise.
    • If try_lock_for(duration) succeeds, prior unlock() operations on the same object synchronize-with this operation (equivalent to release-acquire std::memory_order).
    • The behavior is undefined if the calling thread already owns the mutex (except if m is std::recursive_timed_mutex).
    • An exception may be thrown by clock, time point, or duration during the execution (clocks, time points, and durations provided by the standard library never throw).
  • 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. If time_point already passed, attempts to obtain the ownership without blocking (as if by try_lock()). Otherwise, this function blocks until the mutex is acquired or until the time specified by time_point passes. It returns before time_point only if it succeeds, but it is allowed to fail to acquire the mutex even if at some point in time before time_point it was not owned by another thread. In any case, it returns true if the mutex was acquired and false otherwise.
    • If try_lock_until(time_point) succeeds, prior unlock() operations on the same object synchronize-with this operation (equivalent to release-acquire std::memory_order).
    • The behavior is undefined if the calling thread already owns the mutex (except if m is std::recursive_timed_mutex).
    • An exception may be thrown by clock, time point, or duration during the execution (clocks, time points, and durations provided by the standard library never throw).

Library types

The following standard library types satisfy TimedMutex:

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DRApplied toBehavior as publishedCorrect behavior
LWG 2093C++11timeout-related exceptions were missing in the specificationmentioned