From Jason Turner

[thread.thread.class]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp5pzvgn83/{from.md → to.md} +52 -45
tmp/tmp5pzvgn83/{from.md → to.md} RENAMED
@@ -7,21 +7,23 @@ thread. A `thread` object uniquely represents a particular thread of
7
  execution. That representation may be transferred to other `thread`
8
  objects in such a way that no two `thread` objects simultaneously
9
  represent the same thread of execution. A thread of execution is
10
  *detached* when no `thread` object represents that thread. Objects of
11
  class `thread` can be in a state that does not represent a thread of
12
- execution. A `thread` object does not represent a thread of execution
 
 
13
  after default construction, after being moved from, or after a
14
- successful call to `detach` or `join`.
15
 
16
  ``` cpp
17
  namespace std {
18
  class thread {
19
  public:
20
  // types:
21
  class id;
22
- typedef implementation-defined native_handle_type; // See~[thread.req.native]
23
 
24
  // construct/copy/destroy:
25
  thread() noexcept;
26
  template <class F, class... Args> explicit thread(F&& f, Args&&... args);
27
  ~thread();
@@ -73,19 +75,19 @@ namespace std {
73
  An object of type `thread::id` provides a unique identifier for each
74
  thread of execution and a single distinct value for all `thread` objects
75
  that do not represent a thread of execution ([[thread.thread.class]]).
76
  Each thread of execution has an associated `thread::id` object that is
77
  not equal to the `thread::id` object of any other thread of execution
78
- and that is not equal to the `thread::id` object of any `std::thread`
79
- object that does not represent threads of execution.
80
 
81
  `thread::id` shall be a trivially copyable class (Clause  [[class]]).
82
  The library may reuse the value of a `thread::id` of a terminated thread
83
  that can no longer be joined.
84
 
85
- Relational operators allow `thread::id` objects to be used as keys in
86
- associative containers.
87
 
88
  ``` cpp
89
  id() noexcept;
90
  ```
91
 
@@ -116,78 +118,80 @@ described in  [[alg.sorting]].
116
 
117
  ``` cpp
118
  bool operator<=(thread::id x, thread::id y) noexcept;
119
  ```
120
 
121
- *Returns:* `!(y < x)`
122
 
123
  ``` cpp
124
  bool operator>(thread::id x, thread::id y) noexcept;
125
  ```
126
 
127
- *Returns:* `y < x`
128
 
129
  ``` cpp
130
  bool operator>=(thread::id x, thread::id y) noexcept;
131
  ```
132
 
133
- *Returns:* `!(x < y)`
134
 
135
  ``` cpp
136
  template<class charT, class traits>
137
  basic_ostream<charT, traits>&
138
- operator<< (basic_ostream<charT, traits>&& out, thread::id id);
139
  ```
140
 
141
  *Effects:* Inserts an unspecified text representation of `id` into
142
  `out`. For two objects of type `thread::id` `x` and `y`, if `x == y` the
143
  `thread::id` objects shall have the same text representation and if
144
  `x != y` the `thread::id` objects shall have distinct text
145
  representations.
146
 
147
- *Returns:* `out`
148
 
149
  ``` cpp
150
  template <> struct hash<thread::id>;
151
  ```
152
 
153
- The template specialization shall meet the requirements of class
154
- template `hash` ([[unord.hash]]).
155
 
156
  #### `thread` constructors <a id="thread.thread.constr">[[thread.thread.constr]]</a>
157
 
158
  ``` cpp
159
  thread() noexcept;
160
  ```
161
 
162
  *Effects:* Constructs a `thread` object that does not represent a thread
163
  of execution.
164
 
165
- `get_id() == id()`
166
 
167
  ``` cpp
168
  template <class F, class... Args> explicit thread(F&& f, Args&&... args);
169
  ```
170
 
171
  *Requires:*  `F` and each `Ti` in `Args` shall satisfy the
172
- `MoveConstructible` requirements. *`INVOKE`*`(`*`DECAY_COPY`*`(`
173
- `std::forward<F>(f)), `*`DECAY_COPY`*`(std::forward<Args>(args))...)` ([[func.require]])
174
  shall be a valid expression.
175
 
176
  *Remarks:* This constructor shall not participate in overload resolution
177
  if `decay_t<F>` is the same type as `std::thread`.
178
 
179
  *Effects:*  Constructs an object of type `thread`. The new thread of
180
  execution executes
181
- *`INVOKE`*`(`*`DECAY_COPY`*`(` `std::forward<F>(f)), `*`DECAY_COPY`*`(std::forward<Args>(args))...)`
182
  with the calls to *`DECAY_COPY`* being evaluated in the constructing
183
- thread. Any return value from this invocation is ignored. This implies
184
- that any exceptions not thrown from the invocation of the copy of `f`
185
- will be thrown in the constructing thread, not the new thread. If the
186
- invocation of *`INVOKE`*`(`*`DECAY_COPY`*`(`
187
- `std::forward<F>(f)), `*`DECAY_COPY`*`(std::forward<Args>(args))...)`
188
- terminates with an uncaught exception, `std::terminate` shall be called.
 
 
 
189
 
190
  *Synchronization:* The completion of the invocation of the constructor
191
  synchronizes with the beginning of the invocation of the copy of `f`.
192
 
193
  *Postconditions:* `get_id() != id()`. `*this` represents the newly
@@ -215,30 +219,31 @@ of `x.get_id()` prior to the start of construction.
215
 
216
  ``` cpp
217
  ~thread();
218
  ```
219
 
220
- If `joinable()`, calls `std::terminate()`. Otherwise, has no effects.
221
- Either implicitly detaching or joining a `joinable()` thread in its
222
- destructor could result in difficult to debug correctness (for detach)
223
- or performance (for join) bugs encountered only when an exception is
224
- raised. Thus the programmer must ensure that the destructor is never
225
- executed while the thread is still joinable.
 
226
 
227
  #### `thread` assignment <a id="thread.thread.assign">[[thread.thread.assign]]</a>
228
 
229
  ``` cpp
230
  thread& operator=(thread&& x) noexcept;
231
  ```
232
 
233
- *Effects:* If `joinable()`, calls `std::terminate()`. Otherwise, assigns
234
- the state of `x` to `*this` and sets `x` to a default constructed state.
235
 
236
  *Postconditions:* `x.get_id() == id()` and `get_id()` returns the value
237
  of `x.get_id()` prior to the assignment.
238
 
239
- *Returns:* `*this`
240
 
241
  #### `thread` members <a id="thread.thread.member">[[thread.thread.member]]</a>
242
 
243
  ``` cpp
244
  void swap(thread& x) noexcept;
@@ -248,51 +253,49 @@ void swap(thread& x) noexcept;
248
 
249
  ``` cpp
250
  bool joinable() const noexcept;
251
  ```
252
 
253
- *Returns:* `get_id() != id()`
254
 
255
  ``` cpp
256
  void join();
257
  ```
258
 
259
- `joinable()` is `true`.
260
-
261
  *Effects:*  Blocks until the thread represented by `*this` has
262
  completed.
263
 
264
  *Synchronization:* The completion of the thread represented by `*this`
265
  synchronizes with ([[intro.multithread]]) the corresponding successful
266
- `join()` return. Operations on `*this` are not synchronized.
 
 
267
 
268
  *Postconditions:* The thread represented by `*this` has completed.
269
  `get_id() == id()`.
270
 
271
  *Throws:* `system_error` when an exception is
272
  required ([[thread.req.exception]]).
273
 
274
  *Error conditions:*
275
 
276
  - `resource_deadlock_would_occur` — if deadlock is detected or
277
- `this->get_id() == std::this_thread::get_id()`.
278
  - `no_such_process` — if the thread is not valid.
279
  - `invalid_argument` — if the thread is not joinable.
280
 
281
  ``` cpp
282
  void detach();
283
  ```
284
 
285
- `joinable()` is `true`.
286
-
287
  *Effects:* The thread represented by `*this` continues execution without
288
  the calling thread blocking. When `detach()` returns, `*this` no longer
289
  represents the possibly continuing thread of execution. When the thread
290
  previously represented by `*this` ends execution, the implementation
291
  shall release any owned resources.
292
 
293
- `get_id() == id()`.
294
 
295
  *Throws:* `system_error` when an exception is
296
  required ([[thread.req.exception]]).
297
 
298
  *Error conditions:*
@@ -312,17 +315,21 @@ execution represented by `*this`.
312
 
313
  ``` cpp
314
  unsigned hardware_concurrency() noexcept;
315
  ```
316
 
317
- *Returns:* The number of hardware thread contexts. This value should
318
- only be considered to be a hint. If this value is not computable or well
319
- defined an implementation should return 0.
 
 
 
 
320
 
321
  #### `thread` specialized algorithms <a id="thread.thread.algorithm">[[thread.thread.algorithm]]</a>
322
 
323
  ``` cpp
324
  void swap(thread& x, thread& y) noexcept;
325
  ```
326
 
327
- *Effects:* `x.swap(y)`
328
 
 
7
  execution. That representation may be transferred to other `thread`
8
  objects in such a way that no two `thread` objects simultaneously
9
  represent the same thread of execution. A thread of execution is
10
  *detached* when no `thread` object represents that thread. Objects of
11
  class `thread` can be in a state that does not represent a thread of
12
+ execution.
13
+
14
+ [*Note 1*: A `thread` object does not represent a thread of execution
15
  after default construction, after being moved from, or after a
16
+ successful call to `detach` or `join`. — *end note*]
17
 
18
  ``` cpp
19
  namespace std {
20
  class thread {
21
  public:
22
  // types:
23
  class id;
24
+ using native_handle_type = implementation-defined; // See~[thread.req.native]
25
 
26
  // construct/copy/destroy:
27
  thread() noexcept;
28
  template <class F, class... Args> explicit thread(F&& f, Args&&... args);
29
  ~thread();
 
75
  An object of type `thread::id` provides a unique identifier for each
76
  thread of execution and a single distinct value for all `thread` objects
77
  that do not represent a thread of execution ([[thread.thread.class]]).
78
  Each thread of execution has an associated `thread::id` object that is
79
  not equal to the `thread::id` object of any other thread of execution
80
+ and that is not equal to the `thread::id` object of any `thread` object
81
+ that does not represent threads of execution.
82
 
83
  `thread::id` shall be a trivially copyable class (Clause  [[class]]).
84
  The library may reuse the value of a `thread::id` of a terminated thread
85
  that can no longer be joined.
86
 
87
+ [*Note 1*: Relational operators allow `thread::id` objects to be used
88
+ as keys in associative containers. — *end note*]
89
 
90
  ``` cpp
91
  id() noexcept;
92
  ```
93
 
 
118
 
119
  ``` cpp
120
  bool operator<=(thread::id x, thread::id y) noexcept;
121
  ```
122
 
123
+ *Returns:* `!(y < x)`.
124
 
125
  ``` cpp
126
  bool operator>(thread::id x, thread::id y) noexcept;
127
  ```
128
 
129
+ *Returns:* `y < x`.
130
 
131
  ``` cpp
132
  bool operator>=(thread::id x, thread::id y) noexcept;
133
  ```
134
 
135
+ *Returns:* `!(x < y)`.
136
 
137
  ``` cpp
138
  template<class charT, class traits>
139
  basic_ostream<charT, traits>&
140
+ operator<< (basic_ostream<charT, traits>& out, thread::id id);
141
  ```
142
 
143
  *Effects:* Inserts an unspecified text representation of `id` into
144
  `out`. For two objects of type `thread::id` `x` and `y`, if `x == y` the
145
  `thread::id` objects shall have the same text representation and if
146
  `x != y` the `thread::id` objects shall have distinct text
147
  representations.
148
 
149
+ *Returns:* `out`.
150
 
151
  ``` cpp
152
  template <> struct hash<thread::id>;
153
  ```
154
 
155
+ The specialization is enabled ([[unord.hash]]).
 
156
 
157
  #### `thread` constructors <a id="thread.thread.constr">[[thread.thread.constr]]</a>
158
 
159
  ``` cpp
160
  thread() noexcept;
161
  ```
162
 
163
  *Effects:* Constructs a `thread` object that does not represent a thread
164
  of execution.
165
 
166
+ *Postconditions:* `get_id() == id()`.
167
 
168
  ``` cpp
169
  template <class F, class... Args> explicit thread(F&& f, Args&&... args);
170
  ```
171
 
172
  *Requires:*  `F` and each `Ti` in `Args` shall satisfy the
173
+ `MoveConstructible` requirements.
174
+ ` `*`INVOKE`*`( `*`DECAY_COPY`*`( std::forward<F>(f)), `*`DECAY_COPY`*`( std::forward<Args>(args))...)` ([[func.require]])
175
  shall be a valid expression.
176
 
177
  *Remarks:* This constructor shall not participate in overload resolution
178
  if `decay_t<F>` is the same type as `std::thread`.
179
 
180
  *Effects:*  Constructs an object of type `thread`. The new thread of
181
  execution executes
182
+ ` `*`INVOKE`*`( `*`DECAY_COPY`*`( std::forward<F>(f)), `*`DECAY_COPY`*`( std::forward<Args>(args))...)`
183
  with the calls to *`DECAY_COPY`* being evaluated in the constructing
184
+ thread. Any return value from this invocation is ignored.
185
+
186
+ [*Note 1*: This implies that any exceptions not thrown from the
187
+ invocation of the copy of `f` will be thrown in the constructing thread,
188
+ not the new thread. — *end note*]
189
+
190
+ If the invocation of
191
+ ` `*`INVOKE`*`( `*`DECAY_COPY`*`( std::forward<F>(f)), `*`DECAY_COPY`*`( std::forward<Args>(args))...)`
192
+ terminates with an uncaught exception, `terminate` shall be called.
193
 
194
  *Synchronization:* The completion of the invocation of the constructor
195
  synchronizes with the beginning of the invocation of the copy of `f`.
196
 
197
  *Postconditions:* `get_id() != id()`. `*this` represents the newly
 
219
 
220
  ``` cpp
221
  ~thread();
222
  ```
223
 
224
+ If `joinable()`, calls `terminate()`. Otherwise, has no effects.
225
+
226
+ [*Note 1*: Either implicitly detaching or joining a `joinable()` thread
227
+ in its destructor could result in difficult to debug correctness (for
228
+ detach) or performance (for join) bugs encountered only when an
229
+ exception is thrown. Thus the programmer must ensure that the destructor
230
+ is never executed while the thread is still joinable. — *end note*]
231
 
232
  #### `thread` assignment <a id="thread.thread.assign">[[thread.thread.assign]]</a>
233
 
234
  ``` cpp
235
  thread& operator=(thread&& x) noexcept;
236
  ```
237
 
238
+ *Effects:* If `joinable()`, calls `terminate()`. Otherwise, assigns the
239
+ state of `x` to `*this` and sets `x` to a default constructed state.
240
 
241
  *Postconditions:* `x.get_id() == id()` and `get_id()` returns the value
242
  of `x.get_id()` prior to the assignment.
243
 
244
+ *Returns:* `*this`.
245
 
246
  #### `thread` members <a id="thread.thread.member">[[thread.thread.member]]</a>
247
 
248
  ``` cpp
249
  void swap(thread& x) noexcept;
 
253
 
254
  ``` cpp
255
  bool joinable() const noexcept;
256
  ```
257
 
258
+ *Returns:* `get_id() != id()`.
259
 
260
  ``` cpp
261
  void join();
262
  ```
263
 
 
 
264
  *Effects:*  Blocks until the thread represented by `*this` has
265
  completed.
266
 
267
  *Synchronization:* The completion of the thread represented by `*this`
268
  synchronizes with ([[intro.multithread]]) the corresponding successful
269
+ `join()` return.
270
+
271
+ [*Note 1*: Operations on `*this` are not synchronized. — *end note*]
272
 
273
  *Postconditions:* The thread represented by `*this` has completed.
274
  `get_id() == id()`.
275
 
276
  *Throws:* `system_error` when an exception is
277
  required ([[thread.req.exception]]).
278
 
279
  *Error conditions:*
280
 
281
  - `resource_deadlock_would_occur` — if deadlock is detected or
282
+ `get_id() == this_thread::get_id()`.
283
  - `no_such_process` — if the thread is not valid.
284
  - `invalid_argument` — if the thread is not joinable.
285
 
286
  ``` cpp
287
  void detach();
288
  ```
289
 
 
 
290
  *Effects:* The thread represented by `*this` continues execution without
291
  the calling thread blocking. When `detach()` returns, `*this` no longer
292
  represents the possibly continuing thread of execution. When the thread
293
  previously represented by `*this` ends execution, the implementation
294
  shall release any owned resources.
295
 
296
+ *Postconditions:* `get_id() == id()`.
297
 
298
  *Throws:* `system_error` when an exception is
299
  required ([[thread.req.exception]]).
300
 
301
  *Error conditions:*
 
315
 
316
  ``` cpp
317
  unsigned hardware_concurrency() noexcept;
318
  ```
319
 
320
+ *Returns:* The number of hardware thread contexts.
321
+
322
+ [*Note 1*: This value should only be considered to be a
323
+ hint. — *end note*]
324
+
325
+ If this value is not computable or well defined an implementation should
326
+ return 0.
327
 
328
  #### `thread` specialized algorithms <a id="thread.thread.algorithm">[[thread.thread.algorithm]]</a>
329
 
330
  ``` cpp
331
  void swap(thread& x, thread& y) noexcept;
332
  ```
333
 
334
+ *Effects:* As if by `x.swap(y)`.
335