Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

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

      TheMutex requirements extends theLockable requirements to include inter-thread synchronization.

      Contents

      [edit]Requirements

      For an objectm ofMutex type:

      • The expressionm.lock() has the following properties
      • Behaves as an atomic operation.
      • Blocks the calling thread until exclusive ownership of the mutex can be obtained.
      • Priorm.unlock() operations on the same mutexsynchronize-with this lock operation (equivalent to release-acquirestd::memory_order).
      • The behavior is undefined if the calling thread already owns the mutex (except if m isstd::recursive_mutex orstd::recursive_timed_mutex).
      • Exception of typestd::system_error may be thrown on errors, with the following error codes:
      • The expressionm.try_lock() has the following properties
      • Behaves as an atomic operation.
      • Attempts to obtain exclusive ownership of the mutex for the calling thread without blocking. If ownership is not obtained, returns immediately. The function is allowed to spuriously fail and return even if the mutex is not currently owned by another thread.
      • Iftry_lock() succeeds, priorunlock() operations on the same objectsynchronize-with this operation (equivalent to release-acquirestd::memory_order).lock() does not synchronize with a failedtry_lock().
      • Does not throw exceptions.
      • The expressionm.unlock() has the following properties
      • Behaves as an atomic operation.
      • Releases the calling thread's ownership of the mutex andsynchronizes-with the subsequent successful lock operations on the same object.
      • The behavior is undefined if the calling thread does not own the mutex.
      • Does not throw exceptions.
      • All lock and unlock operations on a single mutex occur in a single total order that can be viewed asmodification order of an atomic variable: the order is specific to this individual mutex.

      [edit]Standard library

      The following standard library types satisfyMutex requirements:

      (C++11)
      provides basic mutual exclusion facility
      (class)[edit]
      provides mutual exclusion facility which can be locked recursively by the same thread
      (class)[edit]
      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
      (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 2309C++11lock might throwstd::system_error
      with error codestd::errc::device_or_resource_busy
      not allowed

      [edit]See also

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

      [8]ページ先頭

      ©2009-2025 Movatter.jp