From Jason Turner

[thread.lock.general]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpjow36hz9/{from.md → to.md} +31 -0
tmp/tmpjow36hz9/{from.md → to.md} RENAMED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### General <a id="thread.lock.general">[[thread.lock.general]]</a>
2
+
3
+ A *lock* is an object that holds a reference to a lockable object and
4
+ may unlock the lockable object during the lock’s destruction (such as
5
+ when leaving block scope). An execution agent may use a lock to aid in
6
+ managing ownership of a lockable object in an exception safe manner. A
7
+ lock is said to *own* a lockable object if it is currently managing the
8
+ ownership of that lockable object for an execution agent. A lock does
9
+ not manage the lifetime of the lockable object it references.
10
+
11
+ [*Note 1*: Locks are intended to ease the burden of unlocking the
12
+ lockable object under both normal and exceptional
13
+ circumstances. — *end note*]
14
+
15
+ Some lock constructors take tag types which describe what should be done
16
+ with the lockable object during the lock’s construction.
17
+
18
+ ``` cpp
19
+ namespace std {
20
+ struct defer_lock_t { }; // do not acquire ownership of the mutex
21
+ struct try_to_lock_t { }; // try to acquire ownership of the mutex
22
+ // without blocking
23
+ struct adopt_lock_t { }; // assume the calling thread has already
24
+ // obtained mutex ownership and manage it
25
+
26
+ inline constexpr defer_lock_t defer_lock { };
27
+ inline constexpr try_to_lock_t try_to_lock { };
28
+ inline constexpr adopt_lock_t adopt_lock { };
29
+ }
30
+ ```
31
+