From Jason Turner

[thread.thread.class]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpbp8genin/{from.md → to.md} +52 -23
tmp/tmpbp8genin/{from.md → to.md} RENAMED
@@ -1,7 +1,9 @@
1
  ### Class `thread` <a id="thread.thread.class">[[thread.thread.class]]</a>
2
 
 
 
3
  The class `thread` provides a mechanism to create a new thread of
4
  execution, to join with a thread (i.e., wait for a thread to complete),
5
  and to perform other operations that manage and query the state of a
6
  thread. A `thread` object uniquely represents a particular thread of
7
  execution. That representation may be transferred to other `thread`
@@ -17,11 +19,11 @@ 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;
@@ -30,11 +32,11 @@ namespace std {
30
  thread(const thread&) = delete;
31
  thread(thread&&) noexcept;
32
  thread& operator=(const thread&) = delete;
33
  thread& operator=(thread&&) noexcept;
34
 
35
- // members
36
  void swap(thread&) noexcept;
37
  bool joinable() const noexcept;
38
  void join();
39
  void detach();
40
  id get_id() const noexcept;
@@ -60,10 +62,12 @@ namespace std {
60
 
61
  template<class charT, class traits>
62
  basic_ostream<charT, traits>&
63
  operator<<(basic_ostream<charT, traits>& out, thread::id id);
64
 
 
 
65
  // hash support
66
  template<class T> struct hash;
67
  template<> struct hash<thread::id>;
68
  }
69
  ```
@@ -74,10 +78,16 @@ that do not represent a thread of execution [[thread.thread.class]].
74
  Each thread of execution has an associated `thread::id` object that is
75
  not equal to the `thread::id` object of any other thread of execution
76
  and that is not equal to the `thread::id` object of any `thread` object
77
  that does not represent threads of execution.
78
 
 
 
 
 
 
 
79
  `thread::id` is a trivially copyable class [[class.prop]]. The library
80
  may reuse the value of a `thread::id` of a terminated thread that can no
81
  longer be joined.
82
 
83
  [*Note 1*: Relational operators allow `thread::id` objects to be used
@@ -112,17 +122,37 @@ described in [[alg.sorting]].
112
  template<class charT, class traits>
113
  basic_ostream<charT, traits>&
114
  operator<< (basic_ostream<charT, traits>& out, thread::id id);
115
  ```
116
 
117
- *Effects:* Inserts an unspecified text representation of `id` into
118
- `out`. For two objects of type `thread::id` `x` and `y`, if `x == y` the
119
- `thread::id` objects have the same text representation and if `x != y`
120
- the `thread::id` objects have distinct text representations.
121
 
122
  *Returns:* `out`.
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  ``` cpp
125
  template<> struct hash<thread::id>;
126
  ```
127
 
128
  The specialization is enabled [[unord.hash]].
@@ -144,33 +174,30 @@ template<class F, class... Args> explicit thread(F&& f, Args&&... args);
144
  *Constraints:* `remove_cvref_t<F>` is not the same type as `thread`.
145
 
146
  *Mandates:* The following are all `true`:
147
 
148
  - `is_constructible_v<decay_t<F>, F>`,
149
- - `(is_constructible_v<decay_t<Args>, Args> && ...)`,
150
- - `is_move_constructible_v<decay_t<F>>`,
151
- - `(is_move_constructible_v<decay_t<Args>> && ...)`, and
152
  - `is_invocable_v<decay_t<F>, decay_t<Args>...>`.
153
 
154
- *Preconditions:* `decay_t<F>` and each type in `decay_t<Args>` meet the
155
- *Cpp17MoveConstructible* requirements.
156
-
157
  *Effects:* The new thread of execution executes
158
 
159
  ``` cpp
160
- invoke(decay-copy(std::forward<F>(f)), decay-copy(std::forward<Args>(args))...)
 
161
  ```
162
 
163
- with the calls to *`decay-copy`* being evaluated in the constructing
164
- thread. Any return value from this invocation is ignored.
 
165
 
166
  [*Note 1*: This implies that any exceptions not thrown from the
167
  invocation of the copy of `f` will be thrown in the constructing thread,
168
  not the new thread. — *end note*]
169
 
170
  If the invocation of `invoke` terminates with an uncaught exception,
171
- `terminate` is called.
172
 
173
  *Synchronization:* The completion of the invocation of the constructor
174
  synchronizes with the beginning of the invocation of the copy of `f`.
175
 
176
  *Ensures:* `get_id() != id()`. `*this` represents the newly started
@@ -195,27 +222,29 @@ thread(thread&& x) noexcept;
195
 
196
  ``` cpp
197
  ~thread();
198
  ```
199
 
200
- *Effects:* If `joinable()`, calls `terminate()`. Otherwise, has no
201
- effects.
202
 
203
  [*Note 1*: Either implicitly detaching or joining a `joinable()` thread
204
- in its destructor could result in difficult to debug correctness (for
205
  detach) or performance (for join) bugs encountered only when an
206
- exception is thrown. Thus the programmer must ensure that the destructor
207
- is never executed while the thread is still joinable. — *end note*]
 
208
 
209
  #### Assignment <a id="thread.thread.assign">[[thread.thread.assign]]</a>
210
 
211
  ``` cpp
212
  thread& operator=(thread&& x) noexcept;
213
  ```
214
 
215
- *Effects:* If `joinable()`, calls `terminate()`. Otherwise, assigns the
216
- state of `x` to `*this` and sets `x` to a default constructed state.
 
217
 
218
  *Ensures:* `x.get_id() == id()` and `get_id()` returns the value of
219
  `x.get_id()` prior to the assignment.
220
 
221
  *Returns:* `*this`.
 
1
  ### Class `thread` <a id="thread.thread.class">[[thread.thread.class]]</a>
2
 
3
+ #### General <a id="thread.thread.class.general">[[thread.thread.class.general]]</a>
4
+
5
  The class `thread` provides a mechanism to create a new thread of
6
  execution, to join with a thread (i.e., wait for a thread to complete),
7
  and to perform other operations that manage and query the state of a
8
  thread. A `thread` object uniquely represents a particular thread of
9
  execution. That representation may be transferred to other `thread`
 
19
 
20
  ``` cpp
21
  namespace std {
22
  class thread {
23
  public:
24
+ // [thread.thread.id], class thread::id
25
  class id;
26
  using native_handle_type = implementation-defined; // see~[thread.req.native]
27
 
28
  // construct/copy/destroy
29
  thread() noexcept;
 
32
  thread(const thread&) = delete;
33
  thread(thread&&) noexcept;
34
  thread& operator=(const thread&) = delete;
35
  thread& operator=(thread&&) noexcept;
36
 
37
+ // [thread.thread.member], members
38
  void swap(thread&) noexcept;
39
  bool joinable() const noexcept;
40
  void join();
41
  void detach();
42
  id get_id() const noexcept;
 
62
 
63
  template<class charT, class traits>
64
  basic_ostream<charT, traits>&
65
  operator<<(basic_ostream<charT, traits>& out, thread::id id);
66
 
67
+ template<class charT> struct formatter<thread::id, charT>;
68
+
69
  // hash support
70
  template<class T> struct hash;
71
  template<> struct hash<thread::id>;
72
  }
73
  ```
 
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
+ The *text representation* for the character type `charT` of an object of
84
+ type `thread::id` is an unspecified sequence of `charT` such that, for
85
+ two objects of type `thread::id` `x` and `y`, if `x == y` is `true`, the
86
+ `thread::id` objects have the same text representation, and if `x != y`
87
+ is `true`, the `thread::id` objects have distinct text representations.
88
+
89
  `thread::id` is a trivially copyable class [[class.prop]]. The library
90
  may reuse the value of a `thread::id` of a terminated thread that can no
91
  longer be joined.
92
 
93
  [*Note 1*: Relational operators allow `thread::id` objects to be used
 
122
  template<class charT, class traits>
123
  basic_ostream<charT, traits>&
124
  operator<< (basic_ostream<charT, traits>& out, thread::id id);
125
  ```
126
 
127
+ *Effects:* Inserts the text representation for `charT` of `id` into
128
+ `out`.
 
 
129
 
130
  *Returns:* `out`.
131
 
132
+ ``` cpp
133
+ template<class charT> struct formatter<thread::id, charT>;
134
+ ```
135
+
136
+ `formatter<thread::id, charT>` interprets *format-spec* as a
137
+ *thread-id-format-spec*. The syntax of format specifications is as
138
+ follows:
139
+
140
+ ``` bnf
141
+ thread-id-format-spec
142
+ fill-and-alignₒₚₜ widthₒₚₜ
143
+ ```
144
+
145
+ [*Note 1*: The productions *fill-and-align* and *width* are described
146
+ in [[format.string.std]]. — *end note*]
147
+
148
+ If the *align* option is omitted it defaults to `>`.
149
+
150
+ A `thread::id` object is formatted by writing its text representation
151
+ for `charT` to the output with additional padding and adjustments as
152
+ specified by the format specifiers.
153
+
154
  ``` cpp
155
  template<> struct hash<thread::id>;
156
  ```
157
 
158
  The specialization is enabled [[unord.hash]].
 
174
  *Constraints:* `remove_cvref_t<F>` is not the same type as `thread`.
175
 
176
  *Mandates:* The following are all `true`:
177
 
178
  - `is_constructible_v<decay_t<F>, F>`,
179
+ - `(is_constructible_v<decay_t<Args>, Args> && ...)`, and
 
 
180
  - `is_invocable_v<decay_t<F>, decay_t<Args>...>`.
181
 
 
 
 
182
  *Effects:* The new thread of execution executes
183
 
184
  ``` cpp
185
+ invoke(auto(std::forward<F>(f)), // for invoke, see [func.invoke]
186
+ auto(std::forward<Args>(args))...)
187
  ```
188
 
189
+ with the values produced by `auto` being materialized [[conv.rval]] in
190
+ the constructing thread. Any return value from this invocation is
191
+ ignored.
192
 
193
  [*Note 1*: This implies that any exceptions not thrown from the
194
  invocation of the copy of `f` will be thrown in the constructing thread,
195
  not the new thread. — *end note*]
196
 
197
  If the invocation of `invoke` terminates with an uncaught exception,
198
+ `terminate` is invoked [[except.terminate]].
199
 
200
  *Synchronization:* The completion of the invocation of the constructor
201
  synchronizes with the beginning of the invocation of the copy of `f`.
202
 
203
  *Ensures:* `get_id() != id()`. `*this` represents the newly started
 
222
 
223
  ``` cpp
224
  ~thread();
225
  ```
226
 
227
+ *Effects:* If `joinable()`, invokes `terminate` [[except.terminate]].
228
+ Otherwise, has no effects.
229
 
230
  [*Note 1*: Either implicitly detaching or joining a `joinable()` thread
231
+ in its destructor can result in difficult to debug correctness (for
232
  detach) or performance (for join) bugs encountered only when an
233
+ exception is thrown. These bugs can be avoided by ensuring that the
234
+ destructor is never executed while the thread is still
235
+ joinable. — *end note*]
236
 
237
  #### Assignment <a id="thread.thread.assign">[[thread.thread.assign]]</a>
238
 
239
  ``` cpp
240
  thread& operator=(thread&& x) noexcept;
241
  ```
242
 
243
+ *Effects:* If `joinable()`, invokes `terminate` [[except.terminate]].
244
+ Otherwise, assigns the state of `x` to `*this` and sets `x` to a default
245
+ constructed state.
246
 
247
  *Ensures:* `x.get_id() == id()` and `get_id()` returns the value of
248
  `x.get_id()` prior to the assignment.
249
 
250
  *Returns:* `*this`.