From Jason Turner

[futures.task]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp8ufh6mgx/{from.md → to.md} +100 -72
tmp/tmp8ufh6mgx/{from.md → to.md} RENAMED
@@ -40,86 +40,79 @@ namespace std {
40
  void operator()(ArgTypes... );
41
  void make_ready_at_thread_exit(ArgTypes...);
42
 
43
  void reset();
44
  };
 
45
  template<class R, class... ArgTypes>
46
  void swap(packaged_task<R(ArgTypes...)>& x, packaged_task<R(ArgTypes...)>& y) noexcept;
47
- template <class R, class Alloc>
48
- struct uses_allocator<packaged_task<R>, Alloc>;
49
  }
50
  ```
51
 
52
- #### `packaged_task` member functions <a id="futures.task.members">[[futures.task.members]]</a>
53
 
54
  ``` cpp
55
  packaged_task() noexcept;
56
  ```
57
 
58
- *Effects:* Constructs a `packaged_task` object with no shared state and
59
- no stored task.
60
 
61
  ``` cpp
62
  template<class F>
63
  packaged_task(F&& f);
64
  ```
65
 
66
- *Requires:* *INVOKE*\<R\>(f, t1, t2, ..., tN), where `t1, t2, ..., tN`
67
- are values of the corresponding types in `ArgTypes...`, shall be a valid
68
- expression. Invoking a copy of `f` shall behave the same as invoking
 
 
 
69
  `f`.
70
 
71
- *Remarks:* This constructor shall not participate in overload resolution
72
- if `decay_t<F>` is the same type as `packaged_task<R(ArgTypes...)>`.
73
-
74
  *Effects:* Constructs a new `packaged_task` object with a shared state
75
  and initializes the object’s stored task with `std::forward<F>(f)`.
76
 
77
- *Throws:*
78
-
79
- - Any exceptions thrown by the copy or move constructor of `f`.
80
- - For the first version, `bad_alloc` if memory for the internal data
81
- structures could not be allocated.
82
- - For the second version, any exceptions thrown by
83
- `allocator_traits<Allocator>::template`
84
- `rebind_traits<`*`unspecified`*`>::allocate`.
85
 
86
  ``` cpp
87
  packaged_task(packaged_task&& rhs) noexcept;
88
  ```
89
 
90
- *Effects:* Constructs a new `packaged_task` object and transfers
91
- ownership of `rhs`’s shared state to `*this`, leaving `rhs` with no
92
- shared state. Moves the stored task from `rhs` to `*this`.
93
 
94
- *Postconditions:* `rhs` has no shared state.
95
 
96
  ``` cpp
97
  packaged_task& operator=(packaged_task&& rhs) noexcept;
98
  ```
99
 
100
  *Effects:*
101
 
102
- - Releases any shared state ([[futures.state]]);
103
  - calls `packaged_task(std::move(rhs)).swap(*this)`.
104
 
105
  ``` cpp
106
  ~packaged_task();
107
  ```
108
 
109
- *Effects:* Abandons any shared state ([[futures.state]]).
110
 
111
  ``` cpp
112
  void swap(packaged_task& other) noexcept;
113
  ```
114
 
115
  *Effects:* Exchanges the shared states and stored tasks of `*this` and
116
  `other`.
117
 
118
- *Postconditions:* `*this` has the same shared state and stored task (if
119
- any) as `other` prior to the call to `swap`. `other` has the same shared
120
- state and stored task (if any) as `*this` prior to the call to `swap`.
121
 
122
  ``` cpp
123
  bool valid() const noexcept;
124
  ```
125
 
@@ -130,11 +123,18 @@ future<R> get_future();
130
  ```
131
 
132
  *Returns:* A `future` object that shares the same shared state as
133
  `*this`.
134
 
135
- *Throws:* a `future_error` object if an error occurs.
 
 
 
 
 
 
 
136
 
137
  *Error conditions:*
138
 
139
  - `future_already_retrieved` if `get_future` has already been called on
140
  a `packaged_task` object with the same shared state as `*this`.
@@ -142,19 +142,19 @@ future<R> get_future();
142
 
143
  ``` cpp
144
  void operator()(ArgTypes... args);
145
  ```
146
 
147
- *Effects:* As if by *INVOKE*\<R\>(f, t1, t2, ..., tN), where `f` is the
148
- stored task of `*this` and `t1, t2, ..., tN` are the values in
149
- `args...`. If the task returns normally, the return value is stored as
150
- the asynchronous result in the shared state of `*this`, otherwise the
151
- exception thrown by the task is stored. The shared state of `*this` is
152
- made ready, and any threads blocked in a function waiting for the shared
153
- state of `*this` to become ready are unblocked.
154
 
155
- *Throws:* a `future_error` exception object if there is no shared state
156
  or the stored task has already been invoked.
157
 
158
  *Error conditions:*
159
 
160
  - `promise_already_satisfied` if the stored task has already been
@@ -163,19 +163,19 @@ or the stored task has already been invoked.
163
 
164
  ``` cpp
165
  void make_ready_at_thread_exit(ArgTypes... args);
166
  ```
167
 
168
- *Effects:* As if by *INVOKE*\<R\>(f, t1, t2, ..., tN), where `f` is the
169
- stored task and `t1, t2, ..., tN` are the values in `args...`. If the
170
- task returns normally, the return value is stored as the asynchronous
171
- result in the shared state of `*this`, otherwise the exception thrown by
172
- the task is stored. In either case, this shall be done without making
173
- that state ready ([[futures.state]]) immediately. Schedules the shared
174
- state to be made ready when the current thread exits, after all objects
175
- of thread storage duration associated with the current thread have been
176
- destroyed.
177
 
178
  *Throws:* `future_error` if an error condition occurs.
179
 
180
  *Error conditions:*
181
 
@@ -188,77 +188,99 @@ void reset();
188
  ```
189
 
190
  *Effects:* As if `*this = packaged_task(std::move(f))`, where `f` is the
191
  task stored in `*this`.
192
 
193
- [*Note 1*: This constructs a new shared state for `*this`. The old
194
- state is abandoned ([[futures.state]]). — *end note*]
195
 
196
  *Throws:*
197
 
198
  - `bad_alloc` if memory for the new shared state could not be allocated.
199
  - any exception thrown by the move constructor of the task stored in the
200
  shared state.
201
  - `future_error` with an error condition of `no_state` if `*this` has no
202
  shared state.
203
 
204
- #### `packaged_task` globals <a id="futures.task.nonmembers">[[futures.task.nonmembers]]</a>
205
 
206
  ``` cpp
207
  template<class R, class... ArgTypes>
208
  void swap(packaged_task<R(ArgTypes...)>& x, packaged_task<R(ArgTypes...)>& y) noexcept;
209
  ```
210
 
211
  *Effects:* As if by `x.swap(y)`.
212
 
213
- ``` cpp
214
- template <class R, class Alloc>
215
- struct uses_allocator<packaged_task<R>, Alloc>
216
- : true_type { };
217
- ```
218
-
219
- *Requires:* `Alloc` shall be an Allocator ([[allocator.requirements]]).
220
-
221
  <!-- Link reference definitions -->
222
  [alg.sorting]: algorithms.md#alg.sorting
223
- [allocator.requirements]: library.md#allocator.requirements
224
  [atomics]: atomics.md#atomics
 
225
  [basic.life]: basic.md#basic.life
226
  [basic.stc.thread]: basic.md#basic.stc.thread
227
  [bitmask.types]: library.md#bitmask.types
228
- [class]: class.md#class
229
- [condition_variable.syn]: #condition_variable.syn
 
 
 
 
 
 
230
  [except.terminate]: except.md#except.terminate
231
  [func.require]: utilities.md#func.require
232
  [future.syn]: #future.syn
233
  [futures]: #futures
234
  [futures.async]: #futures.async
235
  [futures.errors]: #futures.errors
236
- [futures.future_error]: #futures.future_error
237
  [futures.overview]: #futures.overview
238
  [futures.promise]: #futures.promise
239
- [futures.shared_future]: #futures.shared_future
240
  [futures.state]: #futures.state
241
  [futures.task]: #futures.task
242
  [futures.task.members]: #futures.task.members
243
  [futures.task.nonmembers]: #futures.task.nonmembers
244
- [futures.unique_future]: #futures.unique_future
245
- [intro.multithread]: intro.md#intro.multithread
 
 
246
  [mutex.syn]: #mutex.syn
247
  [res.on.data.races]: library.md#res.on.data.races
248
  [res.on.exception.handling]: library.md#res.on.exception.handling
249
- [shared_mutex.syn]: #shared_mutex.syn
 
 
 
 
 
 
 
 
 
 
 
250
  [syserr]: diagnostics.md#syserr
251
  [syserr.syserr]: diagnostics.md#syserr.syserr
252
- [tab:thread.lib.summary]: #tab:thread.lib.summary
253
  [thread]: #thread
 
 
254
  [thread.condition]: #thread.condition
255
  [thread.condition.condvar]: #thread.condition.condvar
256
  [thread.condition.condvarany]: #thread.condition.condvarany
257
  [thread.condition.nonmember]: #thread.condition.nonmember
258
- [thread.decaycopy]: #thread.decaycopy
 
 
259
  [thread.general]: #thread.general
 
 
 
 
 
 
 
 
260
  [thread.lock]: #thread.lock
261
  [thread.lock.algorithm]: #thread.lock.algorithm
262
  [thread.lock.guard]: #thread.lock.guard
263
  [thread.lock.scoped]: #thread.lock.scoped
264
  [thread.lock.shared]: #thread.lock.shared
@@ -288,14 +310,20 @@ template <class R, class Alloc>
288
  [thread.req.lockable.req]: #thread.req.lockable.req
289
  [thread.req.lockable.timed]: #thread.req.lockable.timed
290
  [thread.req.native]: #thread.req.native
291
  [thread.req.paramname]: #thread.req.paramname
292
  [thread.req.timing]: #thread.req.timing
 
 
293
  [thread.sharedmutex.class]: #thread.sharedmutex.class
294
  [thread.sharedmutex.requirements]: #thread.sharedmutex.requirements
295
  [thread.sharedtimedmutex.class]: #thread.sharedtimedmutex.class
296
  [thread.sharedtimedmutex.requirements]: #thread.sharedtimedmutex.requirements
 
 
 
 
297
  [thread.syn]: #thread.syn
298
  [thread.thread.algorithm]: #thread.thread.algorithm
299
  [thread.thread.assign]: #thread.thread.assign
300
  [thread.thread.class]: #thread.thread.class
301
  [thread.thread.constr]: #thread.thread.constr
@@ -306,15 +334,15 @@ template <class R, class Alloc>
306
  [thread.thread.this]: #thread.thread.this
307
  [thread.threads]: #thread.threads
308
  [thread.timedmutex.class]: #thread.timedmutex.class
309
  [thread.timedmutex.recursive]: #thread.timedmutex.recursive
310
  [thread.timedmutex.requirements]: #thread.timedmutex.requirements
311
- [time]: utilities.md#time
312
- [time.clock]: utilities.md#time.clock
313
- [time.clock.req]: utilities.md#time.clock.req
314
- [time.duration]: utilities.md#time.duration
315
- [time.point]: utilities.md#time.point
316
  [unord.hash]: utilities.md#unord.hash
317
 
318
  [^1]: All implementations for which standard time units are meaningful
319
  must necessarily have a steady clock within their hardware
320
  implementation.
 
40
  void operator()(ArgTypes... );
41
  void make_ready_at_thread_exit(ArgTypes...);
42
 
43
  void reset();
44
  };
45
+
46
  template<class R, class... ArgTypes>
47
  void swap(packaged_task<R(ArgTypes...)>& x, packaged_task<R(ArgTypes...)>& y) noexcept;
 
 
48
  }
49
  ```
50
 
51
+ #### Member functions <a id="futures.task.members">[[futures.task.members]]</a>
52
 
53
  ``` cpp
54
  packaged_task() noexcept;
55
  ```
56
 
57
+ *Effects:* The object has no shared state and no stored task.
 
58
 
59
  ``` cpp
60
  template<class F>
61
  packaged_task(F&& f);
62
  ```
63
 
64
+ *Constraints:* `remove_cvref_t<F>` is not the same type as
65
+ `packaged_task<R(ArgTypes...)>`.
66
+
67
+ *Mandates:* `is_invocable_r_v<R, F&, ArgTypes...>` is `true`.
68
+
69
+ *Preconditions:* Invoking a copy of `f` behaves the same as invoking
70
  `f`.
71
 
 
 
 
72
  *Effects:* Constructs a new `packaged_task` object with a shared state
73
  and initializes the object’s stored task with `std::forward<F>(f)`.
74
 
75
+ *Throws:* Any exceptions thrown by the copy or move constructor of `f`,
76
+ or `bad_alloc` if memory for the internal data structures could not be
77
+ allocated.
 
 
 
 
 
78
 
79
  ``` cpp
80
  packaged_task(packaged_task&& rhs) noexcept;
81
  ```
82
 
83
+ *Effects:* Transfers ownership of `rhs`’s shared state to `*this`,
84
+ leaving `rhs` with no shared state. Moves the stored task from `rhs` to
85
+ `*this`.
86
 
87
+ *Ensures:* `rhs` has no shared state.
88
 
89
  ``` cpp
90
  packaged_task& operator=(packaged_task&& rhs) noexcept;
91
  ```
92
 
93
  *Effects:*
94
 
95
+ - Releases any shared state [[futures.state]];
96
  - calls `packaged_task(std::move(rhs)).swap(*this)`.
97
 
98
  ``` cpp
99
  ~packaged_task();
100
  ```
101
 
102
+ *Effects:* Abandons any shared state [[futures.state]].
103
 
104
  ``` cpp
105
  void swap(packaged_task& other) noexcept;
106
  ```
107
 
108
  *Effects:* Exchanges the shared states and stored tasks of `*this` and
109
  `other`.
110
 
111
+ *Ensures:* `*this` has the same shared state and stored task (if any) as
112
+ `other` prior to the call to `swap`. `other` has the same shared state
113
+ and stored task (if any) as `*this` prior to the call to `swap`.
114
 
115
  ``` cpp
116
  bool valid() const noexcept;
117
  ```
118
 
 
123
  ```
124
 
125
  *Returns:* A `future` object that shares the same shared state as
126
  `*this`.
127
 
128
+ *Synchronization:* Calls to this function do not introduce data
129
+ races  [[intro.multithread]] with calls to `operator()` or
130
+ `make_ready_at_thread_exit`.
131
+
132
+ [*Note 1*: Such calls need not synchronize with each
133
+ other. — *end note*]
134
+
135
+ *Throws:* A `future_error` object if an error occurs.
136
 
137
  *Error conditions:*
138
 
139
  - `future_already_retrieved` if `get_future` has already been called on
140
  a `packaged_task` object with the same shared state as `*this`.
 
142
 
143
  ``` cpp
144
  void operator()(ArgTypes... args);
145
  ```
146
 
147
+ *Effects:* As if by *INVOKE*\<R\>(f, t₁, t₂, , t$_N$) [[func.require]],
148
+ where `f` is the stored task of `*this` and `t`₁`, t`₂`, `…`, t`$_N$ are
149
+ the values in `args...`. If the task returns normally, the return value
150
+ is stored as the asynchronous result in the shared state of `*this`,
151
+ otherwise the exception thrown by the task is stored. The shared state
152
+ of `*this` is made ready, and any threads blocked in a function waiting
153
+ for the shared state of `*this` to become ready are unblocked.
154
 
155
+ *Throws:* A `future_error` exception object if there is no shared state
156
  or the stored task has already been invoked.
157
 
158
  *Error conditions:*
159
 
160
  - `promise_already_satisfied` if the stored task has already been
 
163
 
164
  ``` cpp
165
  void make_ready_at_thread_exit(ArgTypes... args);
166
  ```
167
 
168
+ *Effects:* As if by *INVOKE*\<R\>(f, t₁, t₂, , t$_N$) [[func.require]],
169
+ where `f` is the stored task and `t`₁`, t`₂`, `…`, t`$_N$ are the values
170
+ in `args...`. If the task returns normally, the return value is stored
171
+ as the asynchronous result in the shared state of `*this`, otherwise the
172
+ exception thrown by the task is stored. In either case, this is done
173
+ without making that state ready [[futures.state]] immediately. Schedules
174
+ the shared state to be made ready when the current thread exits, after
175
+ all objects of thread storage duration associated with the current
176
+ thread have been destroyed.
177
 
178
  *Throws:* `future_error` if an error condition occurs.
179
 
180
  *Error conditions:*
181
 
 
188
  ```
189
 
190
  *Effects:* As if `*this = packaged_task(std::move(f))`, where `f` is the
191
  task stored in `*this`.
192
 
193
+ [*Note 2*: This constructs a new shared state for `*this`. The old
194
+ state is abandoned [[futures.state]]. — *end note*]
195
 
196
  *Throws:*
197
 
198
  - `bad_alloc` if memory for the new shared state could not be allocated.
199
  - any exception thrown by the move constructor of the task stored in the
200
  shared state.
201
  - `future_error` with an error condition of `no_state` if `*this` has no
202
  shared state.
203
 
204
+ #### Globals <a id="futures.task.nonmembers">[[futures.task.nonmembers]]</a>
205
 
206
  ``` cpp
207
  template<class R, class... ArgTypes>
208
  void swap(packaged_task<R(ArgTypes...)>& x, packaged_task<R(ArgTypes...)>& y) noexcept;
209
  ```
210
 
211
  *Effects:* As if by `x.swap(y)`.
212
 
 
 
 
 
 
 
 
 
213
  <!-- Link reference definitions -->
214
  [alg.sorting]: algorithms.md#alg.sorting
 
215
  [atomics]: atomics.md#atomics
216
+ [barrier.syn]: #barrier.syn
217
  [basic.life]: basic.md#basic.life
218
  [basic.stc.thread]: basic.md#basic.stc.thread
219
  [bitmask.types]: library.md#bitmask.types
220
+ [class.prop]: class.md#class.prop
221
+ [condition.variable.syn]: #condition.variable.syn
222
+ [cpp17.allocator]: #cpp17.allocator
223
+ [cpp17.defaultconstructible]: #cpp17.defaultconstructible
224
+ [cpp17.destructible]: #cpp17.destructible
225
+ [cpp17.moveassignable]: #cpp17.moveassignable
226
+ [cpp17.moveconstructible]: #cpp17.moveconstructible
227
+ [defns.block]: intro.md#defns.block
228
  [except.terminate]: except.md#except.terminate
229
  [func.require]: utilities.md#func.require
230
  [future.syn]: #future.syn
231
  [futures]: #futures
232
  [futures.async]: #futures.async
233
  [futures.errors]: #futures.errors
234
+ [futures.future.error]: #futures.future.error
235
  [futures.overview]: #futures.overview
236
  [futures.promise]: #futures.promise
237
+ [futures.shared.future]: #futures.shared.future
238
  [futures.state]: #futures.state
239
  [futures.task]: #futures.task
240
  [futures.task.members]: #futures.task.members
241
  [futures.task.nonmembers]: #futures.task.nonmembers
242
+ [futures.unique.future]: #futures.unique.future
243
+ [intro.multithread]: basic.md#intro.multithread
244
+ [intro.races]: basic.md#intro.races
245
+ [latch.syn]: #latch.syn
246
  [mutex.syn]: #mutex.syn
247
  [res.on.data.races]: library.md#res.on.data.races
248
  [res.on.exception.handling]: library.md#res.on.exception.handling
249
+ [semaphore.syn]: #semaphore.syn
250
+ [shared.mutex.syn]: #shared.mutex.syn
251
+ [stopcallback]: #stopcallback
252
+ [stopcallback.cons]: #stopcallback.cons
253
+ [stopsource]: #stopsource
254
+ [stopsource.cons]: #stopsource.cons
255
+ [stopsource.mem]: #stopsource.mem
256
+ [stopsource.nonmembers]: #stopsource.nonmembers
257
+ [stoptoken]: #stoptoken
258
+ [stoptoken.cons]: #stoptoken.cons
259
+ [stoptoken.mem]: #stoptoken.mem
260
+ [stoptoken.nonmembers]: #stoptoken.nonmembers
261
  [syserr]: diagnostics.md#syserr
262
  [syserr.syserr]: diagnostics.md#syserr.syserr
 
263
  [thread]: #thread
264
+ [thread.barrier]: #thread.barrier
265
+ [thread.barrier.class]: #thread.barrier.class
266
  [thread.condition]: #thread.condition
267
  [thread.condition.condvar]: #thread.condition.condvar
268
  [thread.condition.condvarany]: #thread.condition.condvarany
269
  [thread.condition.nonmember]: #thread.condition.nonmember
270
+ [thread.condvarany.intwait]: #thread.condvarany.intwait
271
+ [thread.condvarany.wait]: #thread.condvarany.wait
272
+ [thread.coord]: #thread.coord
273
  [thread.general]: #thread.general
274
+ [thread.jthread.class]: #thread.jthread.class
275
+ [thread.jthread.cons]: #thread.jthread.cons
276
+ [thread.jthread.mem]: #thread.jthread.mem
277
+ [thread.jthread.special]: #thread.jthread.special
278
+ [thread.jthread.static]: #thread.jthread.static
279
+ [thread.jthread.stop]: #thread.jthread.stop
280
+ [thread.latch]: #thread.latch
281
+ [thread.latch.class]: #thread.latch.class
282
  [thread.lock]: #thread.lock
283
  [thread.lock.algorithm]: #thread.lock.algorithm
284
  [thread.lock.guard]: #thread.lock.guard
285
  [thread.lock.scoped]: #thread.lock.scoped
286
  [thread.lock.shared]: #thread.lock.shared
 
310
  [thread.req.lockable.req]: #thread.req.lockable.req
311
  [thread.req.lockable.timed]: #thread.req.lockable.timed
312
  [thread.req.native]: #thread.req.native
313
  [thread.req.paramname]: #thread.req.paramname
314
  [thread.req.timing]: #thread.req.timing
315
+ [thread.sema]: #thread.sema
316
+ [thread.sema.cnt]: #thread.sema.cnt
317
  [thread.sharedmutex.class]: #thread.sharedmutex.class
318
  [thread.sharedmutex.requirements]: #thread.sharedmutex.requirements
319
  [thread.sharedtimedmutex.class]: #thread.sharedtimedmutex.class
320
  [thread.sharedtimedmutex.requirements]: #thread.sharedtimedmutex.requirements
321
+ [thread.stoptoken]: #thread.stoptoken
322
+ [thread.stoptoken.intro]: #thread.stoptoken.intro
323
+ [thread.stoptoken.syn]: #thread.stoptoken.syn
324
+ [thread.summary]: #thread.summary
325
  [thread.syn]: #thread.syn
326
  [thread.thread.algorithm]: #thread.thread.algorithm
327
  [thread.thread.assign]: #thread.thread.assign
328
  [thread.thread.class]: #thread.thread.class
329
  [thread.thread.constr]: #thread.thread.constr
 
334
  [thread.thread.this]: #thread.thread.this
335
  [thread.threads]: #thread.threads
336
  [thread.timedmutex.class]: #thread.timedmutex.class
337
  [thread.timedmutex.recursive]: #thread.timedmutex.recursive
338
  [thread.timedmutex.requirements]: #thread.timedmutex.requirements
339
+ [time]: time.md#time
340
+ [time.clock]: time.md#time.clock
341
+ [time.clock.req]: time.md#time.clock.req
342
+ [time.duration]: time.md#time.duration
343
+ [time.point]: time.md#time.point
344
  [unord.hash]: utilities.md#unord.hash
345
 
346
  [^1]: All implementations for which standard time units are meaningful
347
  must necessarily have a steady clock within their hardware
348
  implementation.