Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |named req
       
       
      C++ named requirements
       

      TheTimedMutex requirements extend theTimedLockable requirements to include inter-thread synchronization.

      Contents

      [edit]Requirements

      Additionally, for an objectm ofTimedMutex type:

      • The expressionm.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 byduration. Ifduration is less or equalduration.zero(), attempts to obtain the ownership without blocking (as if bytry_lock()). Otherwise, this function blocks until the mutex is acquired or until the time specified byduration passes. It returns withinduration only if it succeeds, but it is allowed to fail to acquire the mutex even if at some point in time duringduration it was not owned by another thread. In any case, it returnstrue if the mutex was acquired andfalse otherwise.
      • Iftry_lock_for(duration) succeeds, priorunlock() operations on the same objectsynchronize-with this operation (equivalent to release-acquirestd::memory_order).
      • The behavior is undefined if the calling thread already owns the mutex (except if m isstd::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 expressionm.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 untiltime_point. Iftime_point already passed, attempts to obtain the ownership without blocking (as if bytry_lock()). Otherwise, this function blocks until the mutex is acquired or until the time specified bytime_point passes. It returns beforetime_point only if it succeeds, but it is allowed to fail to acquire the mutex even if at some point in time beforetime_point it was not owned by another thread. In any case, it returnstrue if the mutex was acquired andfalse otherwise.
      • Iftry_lock_until(time_point) succeeds, priorunlock() operations on the same objectsynchronize-with this operation (equivalent to release-acquirestd::memory_order).
      • The behavior is undefined if the calling thread already owns the mutex (except if m isstd::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).

      [edit]Standard library

      The following standard library types satisfyTimedMutex requirements:

      provides mutual exclusion facility which can be locked recursively
      by the same thread and implements locking with a timeout
      (class)[edit]
      provides shared mutual exclusion facility and implements locking with a timeout
      (class)[edit]
      provides mutual exclusion facility which implements locking with a timeout
      (class)[edit]

      [edit]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

      [edit]See also

      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/named_req/TimedMutex&oldid=177789"

      [8]ページ先頭

      ©2009-2025 Movatter.jp