Difference between revisions of "cpp/named req/Mutex"
From cppreference.com
m (missed "Throws: nothing" for m.try_lock 30.4.1.2[thread.mutex.requirements.mutex]/20) |
(LWG 2309 moved from SG1 to LWG, and was never sensible to begin with) |
||
Line 21: | Line 21: | ||
::* {{lc|std::errc::operation_not_permitted}} if the calling thread does not have required privileges | ::* {{lc|std::errc::operation_not_permitted}} if the calling thread does not have required privileges | ||
::* {{lc|std::errc::resource_deadlock_would_occur}} if the implementation detects that this operation would lead to deadlock | ::* {{lc|std::errc::resource_deadlock_would_occur}} if the implementation detects that this operation would lead to deadlock | ||
+ | {{rev begin}} | ||
+ | {{rev|until=c++17|<!--LWG #2309--> | ||
::* {{lc|std::errc::device_or_resource_busy}} if the mutex is already locked | ::* {{lc|std::errc::device_or_resource_busy}} if the mutex is already locked | ||
+ | }} | ||
+ | {{rev end}} | ||
* The expression {{c|m.try_lock()}} has the following properties | * The expression {{c|m.try_lock()}} has the following properties | ||
:* Behaves as an atomic operation. | :* Behaves as an atomic operation. |
Revision as of 05:17, 20 October 2015
Template:cpp/concept/title Template:cpp/concept/navbar
The Mutex
concept extends the Template:concept concept to include inter-thread synchronization.
Requirements
- Template:concept
- Template:concept
- Template:concept
- not copyable
- not movable
For object m
of Mutex
type.
- The expression m.lock() has the following properties
- Behaves as an atomic operation.
- Blocks the calling thread until exclusive ownership of the mutex can be obtained.
- Prior m.unlock() operations on the same mutex synchronize-with this lock 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_mutex or std::recursive_timed_mutex)
- Exception of type std::system_error may be thrown on errors, with the following error codes:
- std::errc::operation_not_permitted if the calling thread does not have required privileges
- std::errc::resource_deadlock_would_occur if the implementation detects that this operation would lead to deadlock
|
(until C++17) |
- The expression m.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.
- If
try_lock()
succeeds, priorunlock()
operations on the same object synchronize-with this operation (equivalent to release-acquire std::memory_order).lock()
does not synchronize with a failedtry_lock()
- Does not throw exceptions.
- The expression m.unlock() has the following properties
- Behaves as an atomic operation.
- Releases the calling thread's ownership of the mutex and synchronizes-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
Library types
The following standard library types satisfy Template:concept: