From Jason Turner

[thread.condition.condvarany]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp0etoieay/{from.md → to.md} +39 -28
tmp/tmp0etoieay/{from.md → to.md} RENAMED
@@ -1,14 +1,16 @@
1
  ### Class `condition_variable_any` <a id="thread.condition.condvarany">[[thread.condition.condvarany]]</a>
2
 
3
  A `Lock` type shall meet the `BasicLockable` requirements (
4
- [[thread.req.lockable.basic]]). All of the standard mutex types meet
5
- this requirement. If a `Lock` type other than one of the standard mutex
6
- types or a `unique_lock` wrapper for a standard mutex type is used with
 
 
7
  `condition_variable_any`, the user must ensure that any necessary
8
  synchronization is in place with respect to the predicate associated
9
- with the `condition_variable_any` instance.
10
 
11
  ``` cpp
12
  namespace std {
13
  class condition_variable_any {
14
  public:
@@ -57,19 +59,21 @@ required ([[thread.req.exception]]).
57
 
58
  ``` cpp
59
  ~condition_variable_any();
60
  ```
61
 
62
- There shall be no thread blocked on `*this`. That is, all threads shall
63
- have been notified; they may subsequently block on the lock specified in
64
- the wait. This relaxes the usual rules, which would have required all
65
- wait calls to happen before destruction. Only the notification to
66
- unblock the wait must happen before destruction. The user must take care
67
- to ensure that no threads wait on `*this` once the destructor has been
68
- started, especially when the waiting threads are calling the wait
69
- functions in a loop or using the overloads of `wait`, `wait_for`, or
70
- `wait_until` that take a predicate.
 
 
71
 
72
  *Effects:* Destroys the object.
73
 
74
  ``` cpp
75
  void notify_one() noexcept;
@@ -87,27 +91,29 @@ void notify_all() noexcept;
87
  ``` cpp
88
  template <class Lock>
89
  void wait(Lock& lock);
90
  ```
91
 
92
- *Note:* if any of the `wait` functions exits via an exception, it is
93
  unspecified whether the `Lock` is held. One can use a `Lock` type that
94
- allows to query that, such as the `unique_lock` wrapper.
95
 
96
  *Effects:*
97
 
98
  - Atomically calls `lock.unlock()` and blocks on `*this`.
99
  - When unblocked, calls `lock.lock()` (possibly blocking on the lock)
100
  and returns.
101
  - The function will unblock when signaled by a call to `notify_one()`, a
102
  call to `notify_all()`, or spuriously.
103
 
104
  *Remarks:* If the function fails to meet the postcondition,
105
- `std::terminate()` shall be called ([[except.terminate]]). This can
106
- happen if the re-locking of the mutex throws an exception.
107
 
108
- `lock` is locked by the calling thread.
 
 
 
109
 
110
  *Throws:* Nothing.
111
 
112
  ``` cpp
113
  template <class Lock, class Predicate>
@@ -137,14 +143,16 @@ template <class Lock, class Clock, class Duration>
137
  spuriously.
138
  - If the function exits via an exception, `lock.lock()` shall be called
139
  prior to exiting the function.
140
 
141
  *Remarks:* If the function fails to meet the postcondition,
142
- `std::terminate()` shall be called ([[except.terminate]]). This can
143
- happen if the re-locking of the mutex throws an exception.
144
 
145
- `lock` is locked by the calling thread.
 
 
 
146
 
147
  *Returns:* `cv_status::timeout` if the absolute
148
  timeout ([[thread.req.timing]]) specified by `abs_time` expired,
149
  otherwise `cv_status::no_timeout`.
150
 
@@ -164,14 +172,16 @@ return wait_until(lock, chrono::steady_clock::now() + rel_time);
164
  *Returns:* `cv_status::timeout` if the relative
165
  timeout ([[thread.req.timing]]) specified by `rel_time` expired,
166
  otherwise `cv_status::no_timeout`.
167
 
168
  *Remarks:* If the function fails to meet the postcondition,
169
- `std::terminate()` shall be called ([[except.terminate]]). This can
170
- happen if the re-locking of the mutex throws an exception.
171
 
172
- `lock` is locked by the calling thread.
 
 
 
173
 
174
  *Throws:* Timeout-related exceptions ([[thread.req.timing]]).
175
 
176
  ``` cpp
177
  template <class Lock, class Clock, class Duration, class Predicate>
@@ -185,15 +195,16 @@ while (!pred())
185
  if (wait_until(lock, abs_time) == cv_status::timeout)
186
  return pred();
187
  return true;
188
  ```
189
 
190
- There is no blocking if `pred()` is initially `true`, or if the timeout
191
- has already expired.
192
 
193
- The returned value indicates whether the predicate evaluates to `true`
194
- regardless of whether the timeout was triggered.
 
195
 
196
  ``` cpp
197
  template <class Lock, class Rep, class Period, class Predicate>
198
  bool wait_for(Lock& lock, const chrono::duration<Rep, Period>& rel_time, Predicate pred);
199
  ```
 
1
  ### Class `condition_variable_any` <a id="thread.condition.condvarany">[[thread.condition.condvarany]]</a>
2
 
3
  A `Lock` type shall meet the `BasicLockable` requirements (
4
+ [[thread.req.lockable.basic]]).
5
+
6
+ [*Note 1*: All of the standard mutex types meet this requirement. If a
7
+ `Lock` type other than one of the standard mutex types or a
8
+ `unique_lock` wrapper for a standard mutex type is used with
9
  `condition_variable_any`, the user must ensure that any necessary
10
  synchronization is in place with respect to the predicate associated
11
+ with the `condition_variable_any` instance. — *end note*]
12
 
13
  ``` cpp
14
  namespace std {
15
  class condition_variable_any {
16
  public:
 
59
 
60
  ``` cpp
61
  ~condition_variable_any();
62
  ```
63
 
64
+ *Requires:* There shall be no thread blocked on `*this`.
65
+
66
+ [*Note 1*: That is, all threads shall have been notified; they may
67
+ subsequently block on the lock specified in the wait. This relaxes the
68
+ usual rules, which would have required all wait calls to happen before
69
+ destruction. Only the notification to unblock the wait must happen
70
+ before destruction. The user must take care to ensure that no threads
71
+ wait on `*this` once the destructor has been started, especially when
72
+ the waiting threads are calling the wait functions in a loop or using
73
+ the overloads of `wait`, `wait_for`, or `wait_until` that take a
74
+ predicate. — *end note*]
75
 
76
  *Effects:* Destroys the object.
77
 
78
  ``` cpp
79
  void notify_one() noexcept;
 
91
  ``` cpp
92
  template <class Lock>
93
  void wait(Lock& lock);
94
  ```
95
 
96
+ [*Note 2*: If any of the `wait` functions exits via an exception, it is
97
  unspecified whether the `Lock` is held. One can use a `Lock` type that
98
+ allows to query that, such as the `unique_lock` wrapper. — *end note*]
99
 
100
  *Effects:*
101
 
102
  - Atomically calls `lock.unlock()` and blocks on `*this`.
103
  - When unblocked, calls `lock.lock()` (possibly blocking on the lock)
104
  and returns.
105
  - The function will unblock when signaled by a call to `notify_one()`, a
106
  call to `notify_all()`, or spuriously.
107
 
108
  *Remarks:* If the function fails to meet the postcondition,
109
+ `terminate()` shall be called ([[except.terminate]]).
 
110
 
111
+ [*Note 3*: This can happen if the re-locking of the mutex throws an
112
+ exception. — *end note*]
113
+
114
+ *Postconditions:* `lock` is locked by the calling thread.
115
 
116
  *Throws:* Nothing.
117
 
118
  ``` cpp
119
  template <class Lock, class Predicate>
 
143
  spuriously.
144
  - If the function exits via an exception, `lock.lock()` shall be called
145
  prior to exiting the function.
146
 
147
  *Remarks:* If the function fails to meet the postcondition,
148
+ `terminate()` shall be called ([[except.terminate]]).
 
149
 
150
+ [*Note 4*: This can happen if the re-locking of the mutex throws an
151
+ exception. — *end note*]
152
+
153
+ *Postconditions:* `lock` is locked by the calling thread.
154
 
155
  *Returns:* `cv_status::timeout` if the absolute
156
  timeout ([[thread.req.timing]]) specified by `abs_time` expired,
157
  otherwise `cv_status::no_timeout`.
158
 
 
172
  *Returns:* `cv_status::timeout` if the relative
173
  timeout ([[thread.req.timing]]) specified by `rel_time` expired,
174
  otherwise `cv_status::no_timeout`.
175
 
176
  *Remarks:* If the function fails to meet the postcondition,
177
+ `terminate()` shall be called ([[except.terminate]]).
 
178
 
179
+ [*Note 5*: This can happen if the re-locking of the mutex throws an
180
+ exception. — *end note*]
181
+
182
+ *Postconditions:* `lock` is locked by the calling thread.
183
 
184
  *Throws:* Timeout-related exceptions ([[thread.req.timing]]).
185
 
186
  ``` cpp
187
  template <class Lock, class Clock, class Duration, class Predicate>
 
195
  if (wait_until(lock, abs_time) == cv_status::timeout)
196
  return pred();
197
  return true;
198
  ```
199
 
200
+ [*Note 6*: There is no blocking if `pred()` is initially `true`, or if
201
+ the timeout has already expired. — *end note*]
202
 
203
+ [*Note 7*: The returned value indicates whether the predicate evaluates
204
+ to `true` regardless of whether the timeout was
205
+ triggered. — *end note*]
206
 
207
  ``` cpp
208
  template <class Lock, class Rep, class Period, class Predicate>
209
  bool wait_for(Lock& lock, const chrono::duration<Rep, Period>& rel_time, Predicate pred);
210
  ```