Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/named req/SharedLockable"

From cppreference.com
< cpp‎ | named req
m (+C++14 in title)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{cpp/named req/title|SharedLockable}}
+
{{cpp/named req/title|SharedLockable|notes={{mark since c++14}}}}
 
{{cpp/named req/navbar}}
 
{{cpp/named req/navbar}}
  
Line 9: Line 9:
 
{|table class=wikitable
 
{|table class=wikitable
 
|-
 
|-
!Expression||Type||Preconditions||Effects
+
!Expression||Preconditions||Effects||Return value
 
|-
 
|-
 
|{{c|m.lock_shared()}}
 
|{{c|m.lock_shared()}}
 
|
 
|
 +
|Blocks until a lock can be obtained for the current execution agent (thread, process, task).  If an exception is thrown, no lock is obtained.
 
|
 
|
|Blocks until a lock can be obtained for the current execution agent (thread, process, task).  If an exception is thrown, no lock is obtained.
 
 
|-
 
|-
 
|{{c|m.try_lock_shared()}}
 
|{{c|m.try_lock_shared()}}
|{{c|bool}}
 
 
|
 
|
|Attempts to obtained a lock for the current execution agent (thread, process, task) without blocking. If an exception is thrown, no lock is obtained.
+
|Attempts to obtain a lock for the current execution agent (thread, process, task) without blocking. If an exception is thrown, no lock is obtained.
 
+
|{{c|true}} if the lock was obtained, {{c|false}} otherwise
Returns {{c|true}} if and only if the lock is obtained.
+
 
|-
 
|-
 
|{{c|m.unlock_shared()}}
 
|{{c|m.unlock_shared()}}
|
 
 
|The current execution agent holds a shared lock on {{tt|m}}.
 
|The current execution agent holds a shared lock on {{tt|m}}.
 
|Releases the shared lock held by the execution agent.
 
|Releases the shared lock held by the execution agent.
  
 
Throws no exceptions.
 
Throws no exceptions.
 +
|
 
|}
 
|}
  
===Notes===
+
====Shared locks====
The {{tt|lock_shared}} and {{tt|try_lock_shared}} member functions obtain a shared lock on {{tt|m}} on succcess.
+
A lock on an object is said to be ''shared lock'' if it is acquired by a call to {{tt|lock_shared}}, {{tt|try_lock_shared}}, {{tt|try_lock_shared_for}}, or {{tt|try_lock_shared_until}} member function.
  
 
===See also===
 
===See also===
 
* [[cpp/thread|Thread support library]]
 
* [[cpp/thread|Thread support library]]
 
* {{named req|SharedTimedLockable}}
 
* {{named req|SharedTimedLockable}}
 +
* {{named req|SharedMutex}}
  
 
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}
 
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}

Latest revision as of 12:22, 8 November 2022

 
 
C++ named requirements
 

The SharedLockable requirements describe the minimal characteristics of types that provide shared blocking semantics for execution agents (i.e. threads).

[edit] Requirements

For type L to be SharedLockable, the following conditions have to be satisfied for an object m of type L:

Expression Preconditions Effects Return value
m.lock_shared() Blocks until a lock can be obtained for the current execution agent (thread, process, task). If an exception is thrown, no lock is obtained.
m.try_lock_shared() Attempts to obtain a lock for the current execution agent (thread, process, task) without blocking. If an exception is thrown, no lock is obtained. true if the lock was obtained, false otherwise
m.unlock_shared() The current execution agent holds a shared lock on m. Releases the shared lock held by the execution agent.

Throws no exceptions.

[edit] Shared locks

A lock on an object is said to be shared lock if it is acquired by a call to lock_shared, try_lock_shared, try_lock_shared_for, or try_lock_shared_until member function.

[edit] See also