From Jason Turner

[thread.latch.class]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpwwyjojy0/{from.md → to.md} +100 -0
tmp/tmpwwyjojy0/{from.md → to.md} RENAMED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Class `latch` <a id="thread.latch.class">[[thread.latch.class]]</a>
2
+
3
+ ``` cpp
4
+ namespace std {
5
+ class latch {
6
+ public:
7
+ static constexpr ptrdiff_t max() noexcept;
8
+
9
+ constexpr explicit latch(ptrdiff_t expected);
10
+ ~latch();
11
+
12
+ latch(const latch&) = delete;
13
+ latch& operator=(const latch&) = delete;
14
+
15
+ void count_down(ptrdiff_t update = 1);
16
+ bool try_wait() const noexcept;
17
+ void wait() const;
18
+ void arrive_and_wait(ptrdiff_t update = 1);
19
+
20
+ private:
21
+ ptrdiff_t counter; // exposition only
22
+ };
23
+ }
24
+ ```
25
+
26
+ A `latch` maintains an internal counter that is initialized when the
27
+ latch is created. Threads can block on the latch object, waiting for
28
+ counter to be decremented to zero.
29
+
30
+ Concurrent invocations of the member functions of `latch`, other than
31
+ its destructor, do not introduce data races.
32
+
33
+ ``` cpp
34
+ static constexpr ptrdiff_t max() noexcept;
35
+ ```
36
+
37
+ *Returns:* The maximum value of `counter` that the implementation
38
+ supports.
39
+
40
+ ``` cpp
41
+ constexpr explicit latch(ptrdiff_t expected);
42
+ ```
43
+
44
+ *Preconditions:* `expected >= 0` is `true` and `expected <= max()` is
45
+ `true`.
46
+
47
+ *Effects:* Initializes `counter` with `expected`.
48
+
49
+ *Throws:* Nothing.
50
+
51
+ ``` cpp
52
+ void count_down(ptrdiff_t update = 1);
53
+ ```
54
+
55
+ *Preconditions:* `update >= 0` is `true`, and `update <= counter` is
56
+ `true`.
57
+
58
+ *Effects:* Atomically decrements `counter` by `update`. If `counter` is
59
+ equal to zero, unblocks all threads blocked on `*this`.
60
+
61
+ *Synchronization:* Strongly happens before the returns from all calls
62
+ that are unblocked.
63
+
64
+ *Throws:* `system_error` when an exception is
65
+ required [[thread.req.exception]].
66
+
67
+ *Error conditions:* Any of the error conditions allowed for mutex
68
+ types [[thread.mutex.requirements.mutex]].
69
+
70
+ ``` cpp
71
+ bool try_wait() const noexcept;
72
+ ```
73
+
74
+ *Returns:* With very low probability `false`. Otherwise `counter == 0`.
75
+
76
+ ``` cpp
77
+ void wait() const;
78
+ ```
79
+
80
+ *Effects:* If `counter` equals zero, returns immediately. Otherwise,
81
+ blocks on `*this` until a call to `count_down` that decrements `counter`
82
+ to zero.
83
+
84
+ *Throws:* `system_error` when an exception is
85
+ required [[thread.req.exception]].
86
+
87
+ *Error conditions:* Any of the error conditions allowed for mutex
88
+ types [[thread.mutex.requirements.mutex]].
89
+
90
+ ``` cpp
91
+ void arrive_and_wait(ptrdiff_t update = 1);
92
+ ```
93
+
94
+ *Effects:* Equivalent to:
95
+
96
+ ``` cpp
97
+ count_down(update);
98
+ wait();
99
+ ```
100
+