From Jason Turner

[thread.lock.scoped]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmphvhh0k60/{from.md → to.md} +64 -0
tmp/tmphvhh0k60/{from.md → to.md} RENAMED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Class template `scoped_lock` <a id="thread.lock.scoped">[[thread.lock.scoped]]</a>
2
+
3
+ ``` cpp
4
+ namespace std {
5
+ template <class... MutexTypes>
6
+ class scoped_lock {
7
+ public:
8
+ using mutex_type = Mutex; // If MutexTypes... consists of the single type Mutex
9
+
10
+ explicit scoped_lock(MutexTypes&... m);
11
+ explicit scoped_lock(MutexTypes&... m, adopt_lock_t);
12
+ ~scoped_lock();
13
+
14
+ scoped_lock(const scoped_lock&) = delete;
15
+ scoped_lock& operator=(const scoped_lock&) = delete;
16
+
17
+ private:
18
+ tuple<MutexTypes&...> pm; // exposition only
19
+ };
20
+
21
+ template<class... MutexTypes>
22
+ scoped_lock(scoped_lock<MutexTypes...>) -> scoped_lock<MutexTypes...>;
23
+ }
24
+ ```
25
+
26
+ An object of type `scoped_lock` controls the ownership of lockable
27
+ objects within a scope. A `scoped_lock` object maintains ownership of
28
+ lockable objects throughout the `scoped_lock` object’s lifetime (
29
+ [[basic.life]]). The behavior of a program is undefined if the lockable
30
+ objects referenced by `pm` do not exist for the entire lifetime of the
31
+ `scoped_lock` object. When `sizeof...(MutexTypes)` is `1`, the supplied
32
+ `Mutex` type shall meet the `BasicLockable` requirements (
33
+ [[thread.req.lockable.basic]]). Otherwise, each of the mutex types shall
34
+ meet the `Lockable` requirements ([[thread.req.lockable.req]]).
35
+
36
+ ``` cpp
37
+ explicit scoped_lock(MutexTypes&... m);
38
+ ```
39
+
40
+ *Requires:* If a `MutexTypes` type is not a recursive mutex, the calling
41
+ thread does not own the corresponding mutex element of `m`.
42
+
43
+ *Effects:* Initializes `pm` with `tie(m...)`. Then if
44
+ `sizeof...(MutexTypes)` is `0`, no effects. Otherwise if
45
+ `sizeof...(MutexTypes)` is `1`, then `m.lock()`. Otherwise,
46
+ `lock(m...)`.
47
+
48
+ ``` cpp
49
+ explicit scoped_lock(MutexTypes&... m, adopt_lock_t);
50
+ ```
51
+
52
+ *Requires:* The calling thread owns all the mutexes in `m`.
53
+
54
+ *Effects:* Initializes `pm` with `tie(m...)`.
55
+
56
+ *Throws:* Nothing.
57
+
58
+ ``` cpp
59
+ ~scoped_lock();
60
+ ```
61
+
62
+ *Effects:* For all `i` in \[`0`, `sizeof...(MutexTypes)`),
63
+ `get<i>(pm).unlock()`.
64
+