tmp/tmpr4r7h7sp/{from.md → to.md}
RENAMED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
## Stop tokens <a id="thread.stoptoken">[[thread.stoptoken]]</a>
|
| 2 |
|
| 3 |
### Introduction <a id="thread.stoptoken.intro">[[thread.stoptoken.intro]]</a>
|
| 4 |
|
| 5 |
-
|
| 6 |
-
request that an operation stops execution in a timely
|
| 7 |
-
because the result is no longer required. Such a
|
| 8 |
-
*stop request*.
|
| 9 |
|
| 10 |
`stop_source`, `stop_token`, and `stop_callback` implement semantics of
|
| 11 |
shared ownership of a *stop state*. Any `stop_source`, `stop_token`, or
|
| 12 |
`stop_callback` that shares ownership of the same stop state is an
|
| 13 |
*associated* `stop_source`, `stop_token`, or `stop_callback`,
|
|
@@ -49,22 +49,24 @@ namespace std {
|
|
| 49 |
struct nostopstate_t {
|
| 50 |
explicit nostopstate_t() = default;
|
| 51 |
};
|
| 52 |
inline constexpr nostopstate_t nostopstate{};
|
| 53 |
|
| 54 |
-
// [stopcallback], class stop_callback
|
| 55 |
template<class Callback>
|
| 56 |
class stop_callback;
|
| 57 |
}
|
| 58 |
```
|
| 59 |
|
| 60 |
### Class `stop_token` <a id="stoptoken">[[stoptoken]]</a>
|
| 61 |
|
|
|
|
|
|
|
| 62 |
The class `stop_token` provides an interface for querying whether a stop
|
| 63 |
request has been made (`stop_requested`) or can ever be made
|
| 64 |
-
(`stop_possible`) using an associated `stop_source` object
|
| 65 |
-
[[stopsource]]
|
| 66 |
[[stopcallback]] constructor to register a callback to be called when a
|
| 67 |
stop request has been made from an associated `stop_source`.
|
| 68 |
|
| 69 |
``` cpp
|
| 70 |
namespace std {
|
|
@@ -184,14 +186,16 @@ friend void swap(stop_token& x, stop_token& y) noexcept;
|
|
| 184 |
|
| 185 |
*Effects:* Equivalent to: `x.swap(y)`.
|
| 186 |
|
| 187 |
### Class `stop_source` <a id="stopsource">[[stopsource]]</a>
|
| 188 |
|
|
|
|
|
|
|
| 189 |
The class `stop_source` implements the semantics of making a stop
|
| 190 |
request. A stop request made on a `stop_source` object is visible to all
|
| 191 |
-
associated `stop_source` and `stop_token`
|
| 192 |
-
|
| 193 |
request has no effect).
|
| 194 |
|
| 195 |
``` cpp
|
| 196 |
namespace std {
|
| 197 |
// no-shared-stop-state indicator
|
|
@@ -235,12 +239,11 @@ stop_source();
|
|
| 235 |
*Effects:* Initialises `*this` to have ownership of a new stop state.
|
| 236 |
|
| 237 |
*Ensures:* `stop_possible()` is `true` and `stop_requested()` is
|
| 238 |
`false`.
|
| 239 |
|
| 240 |
-
*Throws:* `bad_alloc` if memory
|
| 241 |
-
state.
|
| 242 |
|
| 243 |
``` cpp
|
| 244 |
explicit stop_source(nostopstate_t) noexcept;
|
| 245 |
```
|
| 246 |
|
|
@@ -325,11 +328,11 @@ bool request_stop() noexcept;
|
|
| 325 |
has received a stop request, and if not, makes a stop request. The
|
| 326 |
determination and making of the stop request are an atomic
|
| 327 |
read-modify-write operation [[intro.races]]. If the request was made,
|
| 328 |
the callbacks registered by associated `stop_callback` objects are
|
| 329 |
synchronously called. If an invocation of a callback exits via an
|
| 330 |
-
exception then `terminate` is
|
| 331 |
|
| 332 |
[*Note 1*: A stop request includes notifying all condition variables of
|
| 333 |
type `condition_variable_any` temporarily registered during an
|
| 334 |
interruptible wait [[thread.condvarany.intwait]]. — *end note*]
|
| 335 |
|
|
@@ -354,10 +357,12 @@ friend void swap(stop_source& x, stop_source& y) noexcept;
|
|
| 354 |
|
| 355 |
*Effects:* Equivalent to: `x.swap(y)`.
|
| 356 |
|
| 357 |
### Class template `stop_callback` <a id="stopcallback">[[stopcallback]]</a>
|
| 358 |
|
|
|
|
|
|
|
| 359 |
``` cpp
|
| 360 |
namespace std {
|
| 361 |
template<class Callback>
|
| 362 |
class stop_callback {
|
| 363 |
public:
|
|
@@ -418,15 +423,15 @@ before the constructor returns. Otherwise, if `st` has ownership of a
|
|
| 418 |
stop state, acquires shared ownership of that stop state and registers
|
| 419 |
the callback with that stop state such that
|
| 420 |
`std::forward<Callback>(callback)()` is evaluated by the first call to
|
| 421 |
`request_stop()` on an associated `stop_source`.
|
| 422 |
|
| 423 |
-
*Remarks:* If evaluating `std::forward<Callback>(callback)()` exits via
|
| 424 |
-
an exception, then `terminate` is called [[except.terminate]].
|
| 425 |
-
|
| 426 |
*Throws:* Any exception thrown by the initialization of `callback`.
|
| 427 |
|
|
|
|
|
|
|
|
|
|
| 428 |
``` cpp
|
| 429 |
~stop_callback();
|
| 430 |
```
|
| 431 |
|
| 432 |
*Effects:* Unregisters the callback from the owned stop state, if any.
|
|
|
|
| 1 |
## Stop tokens <a id="thread.stoptoken">[[thread.stoptoken]]</a>
|
| 2 |
|
| 3 |
### Introduction <a id="thread.stoptoken.intro">[[thread.stoptoken.intro]]</a>
|
| 4 |
|
| 5 |
+
Subclause [[thread.stoptoken]] describes components that can be used to
|
| 6 |
+
asynchronously request that an operation stops execution in a timely
|
| 7 |
+
manner, typically because the result is no longer required. Such a
|
| 8 |
+
request is called a *stop request*.
|
| 9 |
|
| 10 |
`stop_source`, `stop_token`, and `stop_callback` implement semantics of
|
| 11 |
shared ownership of a *stop state*. Any `stop_source`, `stop_token`, or
|
| 12 |
`stop_callback` that shares ownership of the same stop state is an
|
| 13 |
*associated* `stop_source`, `stop_token`, or `stop_callback`,
|
|
|
|
| 49 |
struct nostopstate_t {
|
| 50 |
explicit nostopstate_t() = default;
|
| 51 |
};
|
| 52 |
inline constexpr nostopstate_t nostopstate{};
|
| 53 |
|
| 54 |
+
// [stopcallback], class template stop_callback
|
| 55 |
template<class Callback>
|
| 56 |
class stop_callback;
|
| 57 |
}
|
| 58 |
```
|
| 59 |
|
| 60 |
### Class `stop_token` <a id="stoptoken">[[stoptoken]]</a>
|
| 61 |
|
| 62 |
+
#### General <a id="stoptoken.general">[[stoptoken.general]]</a>
|
| 63 |
+
|
| 64 |
The class `stop_token` provides an interface for querying whether a stop
|
| 65 |
request has been made (`stop_requested`) or can ever be made
|
| 66 |
+
(`stop_possible`) using an associated `stop_source` object
|
| 67 |
+
[[stopsource]]. A `stop_token` can also be passed to a `stop_callback`
|
| 68 |
[[stopcallback]] constructor to register a callback to be called when a
|
| 69 |
stop request has been made from an associated `stop_source`.
|
| 70 |
|
| 71 |
``` cpp
|
| 72 |
namespace std {
|
|
|
|
| 186 |
|
| 187 |
*Effects:* Equivalent to: `x.swap(y)`.
|
| 188 |
|
| 189 |
### Class `stop_source` <a id="stopsource">[[stopsource]]</a>
|
| 190 |
|
| 191 |
+
#### General <a id="stopsource.general">[[stopsource.general]]</a>
|
| 192 |
+
|
| 193 |
The class `stop_source` implements the semantics of making a stop
|
| 194 |
request. A stop request made on a `stop_source` object is visible to all
|
| 195 |
+
associated `stop_source` and `stop_token` [[stoptoken]] objects. Once a
|
| 196 |
+
stop request has been made it cannot be withdrawn (a subsequent stop
|
| 197 |
request has no effect).
|
| 198 |
|
| 199 |
``` cpp
|
| 200 |
namespace std {
|
| 201 |
// no-shared-stop-state indicator
|
|
|
|
| 239 |
*Effects:* Initialises `*this` to have ownership of a new stop state.
|
| 240 |
|
| 241 |
*Ensures:* `stop_possible()` is `true` and `stop_requested()` is
|
| 242 |
`false`.
|
| 243 |
|
| 244 |
+
*Throws:* `bad_alloc` if memory cannot be allocated for the stop state.
|
|
|
|
| 245 |
|
| 246 |
``` cpp
|
| 247 |
explicit stop_source(nostopstate_t) noexcept;
|
| 248 |
```
|
| 249 |
|
|
|
|
| 328 |
has received a stop request, and if not, makes a stop request. The
|
| 329 |
determination and making of the stop request are an atomic
|
| 330 |
read-modify-write operation [[intro.races]]. If the request was made,
|
| 331 |
the callbacks registered by associated `stop_callback` objects are
|
| 332 |
synchronously called. If an invocation of a callback exits via an
|
| 333 |
+
exception then `terminate` is invoked [[except.terminate]].
|
| 334 |
|
| 335 |
[*Note 1*: A stop request includes notifying all condition variables of
|
| 336 |
type `condition_variable_any` temporarily registered during an
|
| 337 |
interruptible wait [[thread.condvarany.intwait]]. — *end note*]
|
| 338 |
|
|
|
|
| 357 |
|
| 358 |
*Effects:* Equivalent to: `x.swap(y)`.
|
| 359 |
|
| 360 |
### Class template `stop_callback` <a id="stopcallback">[[stopcallback]]</a>
|
| 361 |
|
| 362 |
+
#### General <a id="stopcallback.general">[[stopcallback.general]]</a>
|
| 363 |
+
|
| 364 |
``` cpp
|
| 365 |
namespace std {
|
| 366 |
template<class Callback>
|
| 367 |
class stop_callback {
|
| 368 |
public:
|
|
|
|
| 423 |
stop state, acquires shared ownership of that stop state and registers
|
| 424 |
the callback with that stop state such that
|
| 425 |
`std::forward<Callback>(callback)()` is evaluated by the first call to
|
| 426 |
`request_stop()` on an associated `stop_source`.
|
| 427 |
|
|
|
|
|
|
|
|
|
|
| 428 |
*Throws:* Any exception thrown by the initialization of `callback`.
|
| 429 |
|
| 430 |
+
*Remarks:* If evaluating `std::forward<Callback>(callback)()` exits via
|
| 431 |
+
an exception, then `terminate` is invoked [[except.terminate]].
|
| 432 |
+
|
| 433 |
``` cpp
|
| 434 |
~stop_callback();
|
| 435 |
```
|
| 436 |
|
| 437 |
*Effects:* Unregisters the callback from the owned stop state, if any.
|