Skip to content

Commit c597ab4

Browse files
authored
Merge pull request #214 from cplusplus/stoppable-exposition-only-concepts
make `stoppable_source` and `stoppable_callback_for` exposition-only
2 parents ff4e562 + ffae82f commit c597ab4

File tree

1 file changed

+95
-94
lines changed

1 file changed

+95
-94
lines changed

execution.bs

Lines changed: 95 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,9 +2419,9 @@ first proposed in [[P2175R0]].
24192419
At a high-level, the facilities proposed by this paper for supporting
24202420
cancellation include:
24212421

2422-
* Add `std::stoppable_token` and `std::stoppable_token_for` concepts that
2423-
generalise the interface of `std::stop_token` type to allow other types with
2424-
different implementation strategies.
2422+
* Add a `std::stoppable_token` concept that generalises the interface of the
2423+
`std::stop_token` type to allow other stop token types with different
2424+
implementation strategies.
24252425
* Add `std::unstoppable_token` concept for detecting whether a `stoppable_token`
24262426
can never receive a stop-request.
24272427
* Add `std::inplace_stop_token`, `std::inplace_stop_source` and
@@ -4120,21 +4120,20 @@ namespace std {
41204120
typically because the result is no longer required. Such a request is called
41214121
a <dfn export=true>stop request</dfn>.
41224122

4123-
2. <code>stop<ins>pable</ins>_source</code>,
4124-
<code>stop<ins>pable</ins>_token</code>, and
4125-
<code>stop<ins>pable</ins>_callback<ins>_for</ins></code>
4126-
<del>implement</del><ins>are concepts that specify the required syntax
4127-
and</ins> semantics of shared <del>ownership</del><ins>access</ins> of a
4128-
<dfn export=true>stop state</dfn>. Any
4129-
<code>stop<ins>pable</ins>_source</code>,
4130-
<code>stop<ins>pable</ins>_token</code>, or
4131-
<code>stop<ins>pable</ins>_callback<ins>_for</ins></code> object that
4132-
<del>shares ownership of</del><ins>refers to</ins> the same stop state is an
4133-
<dfn export=true>associated</dfn> <code>stop<ins>pable</ins>_source</code>,
4134-
<code>stop<ins>pable</ins>_token</code>, or
4135-
<code>stop<ins>pable</ins>_callback<ins>_for</ins></code>, respectively.
4136-
<del>The last remaining owner of the stop state automatically releases the
4137-
resources associated with the stop state.</del>
4123+
2. <del>`stop_source`, `stop_token`, and `stop_callback` implement</del>
4124+
<ins><i>`stoppable-source`</i>, `stoppable_token`, and
4125+
<i>`stoppable-callback-for`</i> are concepts that specify the required
4126+
syntax and</ins> semantics of shared <del>ownership</del><ins>access</ins>
4127+
of a <dfn export=true>stop state</dfn>. <del>Any `stop_source`,
4128+
`stop_token`, or `stop_callback` object that shares ownership of the same
4129+
stop state is an <i>**associated**</i> `stop_source`, `stop_token`, or
4130+
`stop_callback`, respectively.</del> <ins>Any object modeling
4131+
<i>`stoppable-source`</i>, `stoppable_token`, or
4132+
<i>`stoppable-callback-for`</i> that refers to the same stop state is an
4133+
<dfn export=true>associated</dfn> <i>`stoppable-source`</i>,
4134+
`stoppable_token`, or <i>`stoppable-callback-for`</i>,
4135+
respectively.</ins><del> The last remaining owner of the stop state
4136+
automatically releases the resources associated with the stop state.</del>
41384137

41394138
3. A <code>stop<ins>pable</ins>_token</code> can be passed to an operation <del>
41404139
which</del><ins>that</ins> can either
@@ -4147,28 +4146,27 @@ namespace std {
41474146
template which</del><ins>that</ins> will be called in the event that a
41484147
stop request is made.</div>
41494148

4150-
A stop request made via a <code>stop<ins>pable</ins>_source</code> will be
4151-
visible to all associated <code>stop<ins>pable</ins>_token</code> and
4152-
<code>stop<ins>pable</ins>_source</code> objects. Once a stop request has
4153-
been made it cannot be withdrawn (a subsequent stop request has no effect).
4149+
A stop request made via <del>a `stop_source`</del><ins>an object that models
4150+
<i>`stoppable-source`</i></ins> will be visible to all associated
4151+
<code>stop<ins>pable</ins>_token</code> and <del>`stop_source`</del><ins>
4152+
<i>`stoppable-source`</i></ins> objects. Once a stop request has been
4153+
made it cannot be withdrawn (a subsequent stop request has no effect).
41544154

4155-
4. Callbacks registered via a
4156-
<code>stop<ins>pable</ins>_callback<ins>_for</ins></code> object are called
4157-
when a stop request is first made by any associated
4158-
<code>stop<ins>pable</ins>_source</code> object.
4155+
4. Callbacks registered via <del>a `stop_callback` object</del><ins>an object
4156+
that models <i>`stoppable-callback-for`</i></ins> are called when a stop
4157+
request is first made by any associated <del>`stop_source`</del><ins>
4158+
<i>`stoppable-source`</i></ins> object.
41594159

41604160
<span class="ed-note">The following paragraph is moved to the specification of
4161-
the new `stoppable_source` concept.</span>
4161+
the new <i>`stoppable-source`</i> concept.</span>
41624162

41634163
<div class="del">
41644164

41654165
5. Calls to the functions `request_stop`, `stop_requested`, and `stop_possible`
41664166
do not introduce data races. A call to `request_stop` that returns `true`
4167-
synchronizes with a call to `stop_requested` on an associated
4168-
<code>stop<ins>pable</ins>_token</code> or
4169-
<code>stop<ins>pable</ins>_source</code> object that returns `true`.
4170-
Registration of a callback synchronizes with the invocation of that
4171-
callback.
4167+
synchronizes with a call to `stop_requested` on an associated `stop_token`
4168+
or `stop_source` object that returns `true`. Registration of a callback
4169+
synchronizes with the invocation of that callback.
41724170

41734171
</div>
41744172

@@ -4195,7 +4193,7 @@ declarations into the `<stop_token>` synopsis:</span>
41954193
namespace std {
41964194
<div class="block-insert"> <i>// [stoptoken.concepts], stop token concepts</i>
41974195
template&lt;class Callback, class Token, class Initializer = Callback>
4198-
concept stoppable_callback_for = <i>see below</i>;
4196+
concept <i>stoppable-callback-for</i> = <i>see below</i>; <i>// exposition only</i>
41994197

42004198
template&lt;class Token>
42014199
concept stoppable_token = <i>see below</i>;
@@ -4204,7 +4202,7 @@ namespace std {
42044202
concept unstoppable_token = <i>see below</i>;
42054203

42064204
template&lt;class Source>
4207-
concept stoppable_source = <i>see below</i>;</div>
4205+
concept <i>stoppable-source</i> = <i>see below</i>; <i>// exposition only</i></div>
42084206
// 33.3.3, class stop_token
42094207
class stop_token;
42104208

@@ -4253,12 +4251,12 @@ Header `<stop_token>` synopsis <b>[thread.stoptoken.syn]</b> and Class
42534251
arguments, if the type `stop_callback_for_t<Token, Callback>` is valid, it
42544252
denotes the type of a stop callback to use to register a callback to be
42554253
executed if a stop request is ever made on the `stoppable_token`'s
4256-
associated stop source. The `stoppable_callback_for` concept checks for a
4257-
callback compatible with a given stop token type.
4254+
associated stop source. The exposition-only <i>`stoppable-callback-for`</i>
4255+
concept checks for a callback compatible with a given stop token type.
42584256

42594257
<pre highlight="c++">
42604258
template&lt;class Callback, class Token, class Initializer = Callback>
4261-
concept stoppable_callback_for =
4259+
concept <i>stoppable-callback-for</i> = <i>// exposition only</i>
42624260
invocable&lt;Callback> &&
42634261
constructible_from&lt;Callback, Initializer> &&
42644262
requires { typename stop_callback_for_t&lt;Token, Callback>; } &&
@@ -4270,8 +4268,8 @@ Header `<stop_token>` synopsis <b>[thread.stoptoken.syn]</b> and Class
42704268
`Initializer`; and let `CB` denote the type `stop_callback_for_t<Token,
42714269
Callback>`.
42724270

4273-
3. The concept `stoppable_callback_for<Callback, Token, Initializer>` is modeled
4274-
only if:
4271+
3. The concept <code><i>stoppable-callback-for</i>&lt;Callback, Token,
4272+
Initializer></code> is modeled only if:
42754273

42764274
1. The following concepts are modeled:
42774275

@@ -4390,27 +4388,29 @@ Header `<stop_token>` synopsis <b>[thread.stoptoken.syn]</b> and Class
43904388
after `E` shall evaluate to `true`.
43914389

43924390
3. For any types `Callback` and `Initializer`, if
4393-
`stoppable_callback_for<Callback, Token, Initializer>` is satisfied,
4394-
then `stoppable_callback_for<Callback, Token, Initializer>` shall be
4395-
modeled.
4396-
4397-
4. A `stoppable_token` object has at most one associated logical stop state.
4398-
A `stoppable_token` object with no associated stop state is said to be
4399-
<dfn export=true>disengaged</dfn>. For a disengaged `stoppable_token`
4400-
object, `stop_possible` and `stop_requested` shall return `false`. If
4401-
`t` and `u` reference the same stop state, or if both `t` and `u` are
4402-
disengaged, `t == u` shall be `true`; otherwise, it shall be `false`.
4403-
4404-
6. A model of `stoppable_source` can be queried whether stop has been requested
4405-
(`stop_requested`) and whether stop is possible (`stop_possible`). It is a
4406-
factory for associated stop tokens (`get_token`) and can be explicitly
4407-
placed into the "stop requested" state (`request_stop`). It maintains a list
4408-
of registered stop callback invocations that it executes when a stop request
4409-
is first made.
4391+
<code><i>stoppable-callback-for</i>&lt;Callback, Token,
4392+
Initializer></code> is satisfied, then
4393+
<code><i>stoppable-callback-for</i>&lt;Callback, Token,
4394+
Initializer></code> shall be modeled.
4395+
4396+
4. An object that models `stoppable_token` has at most one associated
4397+
logical stop state. A `stoppable_token` object with no associated stop
4398+
state is said to be <dfn export=true>disengaged</dfn>. For a disengaged
4399+
`stoppable_token` object, `stop_possible` and `stop_requested` shall
4400+
return `false`. If `t` and `u` reference the same stop state, or if both
4401+
`t` and `u` are disengaged, `t == u` shall be `true`; otherwise, it
4402+
shall be `false`.
4403+
4404+
6. A model of the exposition-only <i>`stoppable-source`</i> concept can be
4405+
queried whether stop has been requested (`stop_requested`) and whether stop
4406+
is possible (`stop_possible`). It is a factory for associated stop tokens
4407+
(`get_token`) and can be explicitly placed into the "stop requested" state
4408+
(`request_stop`). It maintains a list of registered stop callback
4409+
invocations that it executes when a stop request is first made.
44104410

44114411
<pre highlight="c++">
44124412
template&lt;class Source>
4413-
concept stoppable_source =
4413+
concept <i>stoppable-source</i> = <i>// exposition only</i>
44144414
requires (Source& src, const Source csrc) { <i>// see implicit expression variations</i>
44154415
<i>// ([concepts.equality])</i>
44164416
{ csrc.get_token() } -> stoppable_token;
@@ -4420,14 +4420,15 @@ Header `<stop_token>` synopsis <b>[thread.stoptoken.syn]</b> and Class
44204420
};
44214421
</pre>
44224422

4423-
1. A `stoppable_source` object has at most one associated logical stop
4424-
state. A `stoppable_source` object with no associated stop state is said
4425-
to be disengaged. For a disengaged `stoppable_source` object,
4426-
`stop_possible` and `stop_requested` shall return `false`.
4423+
1. A <i>`stoppable-source`</i> object has at most one associated logical
4424+
stop state. A <i>`stoppable-source`</i> object with no associated stop
4425+
state is said to be disengaged. For a disengaged
4426+
<i>`stoppable-source`</i> object, `stop_possible` and `stop_requested`
4427+
shall return `false`.
44274428

4428-
2. A disengaged `stoppable_source` object shall return a disengaged stop token
4429-
from `get_token()`. Otherwise, `get_token()` shall return a stop token that
4430-
is associated with the stop state of the source.
4429+
2. A disengaged <i>`stoppable-source`</i> object shall return a disengaged
4430+
stop token from `get_token()`. Otherwise, `get_token()` shall return a
4431+
stop token that is associated with the stop state of the source.
44314432

44324433
<span class="ed-note">The following paragraph is moved from the introduction,
44334434
with minor modifications (underlined in green).</span>
@@ -4437,16 +4438,15 @@ Header `<stop_token>` synopsis <b>[thread.stoptoken.syn]</b> and Class
44374438
functions on associated `stoppable_token` objects</ins> do not introduce
44384439
data races. A call to `request_stop` that returns `true` synchronizes
44394440
with a call to `stop_requested` on an associated
4440-
<code>stop<ins>pable</ins>_token</code> or
4441-
<code>stop<ins>pable</ins>_source</code> object that returns `true`.
4442-
Registration of a callback synchronizes with the invocation of that
4443-
callback.
4441+
<code>stop<ins>pable</ins>_token</code> or <del>`stop_source`</del><ins>
4442+
<i>`stoppable-source`</i></ins> object that returns `true`. Registration
4443+
of a callback synchronizes with the invocation of that callback.
44444444

44454445
<span class="ed-note">The following paragraph is taken from
44464446
[[#spec-stopsource.mem]] and modified.</span>
44474447

4448-
4. If the `stoppable_source` is disengaged, `request_stop` shall have no
4449-
effect and return `false`. Otherwise, it shall execute a <dfn
4448+
4. If the <i>`stoppable-source`</i> is disengaged, `request_stop` shall have
4449+
no effect and return `false`. Otherwise, it shall execute a <dfn
44504450
export=true>stop request operation</dfn> on the associated stop state. A
44514451
stop request operation determines whether the stop state has received a
44524452
stop request, and if not, makes a stop request. The determination and
@@ -4638,7 +4638,7 @@ friend void swap(stop_token& x, stop_token& y) noexcept;
46384638
request. A stop request made on a `stop_source` object is visible to all
46394639
associated `stop_source` and `stop_token` ([thread.stoptoken]) objects. Once
46404640
a stop request has been made it cannot be withdrawn (a subsequent stop
4641-
request has no effect)</del><ins>models `stoppable_source`</ins>.
4641+
request has no effect)</del><ins>models <i>`stoppable-source`</i></ins>.
46424642

46434643
<pre highlight="c++">
46444644
namespace std {
@@ -4881,10 +4881,12 @@ namespace std {
48814881

48824882
<div class="ins">
48834883

4884-
3. *Remarks:* For a type `C`, if `stoppable_callback_for<Callback, stop_token,
4885-
C>` is satisfied, then `stoppable_callback_for<Callback, stop_token, C>` is
4886-
modeled. The exposition-only `callback` member is the associated callback
4887-
function ([stoptoken.concepts]) of `stop_callback<Callback>` objects.
4884+
3. *Remarks:* For a type `C`, if
4885+
<code><i>stoppable-callback-for</i>&lt;Callback, stop_token, C></code> is
4886+
satisfied, then <code><i>stoppable-callback-for</i>&lt;Callback, stop_token,
4887+
C></code> is modeled. The exposition-only `callback` member is the
4888+
associated callback function ([stoptoken.concepts]) of
4889+
`stop_callback<Callback>` objects.
48884890

48894891
</div>
48904892

@@ -5056,7 +5058,7 @@ of Stop tokens <b>[thread.stoptoken]</b>.</span>
50565058

50575059
#### General <b>[stopsource.inplace.general]</b> #### {#spec-stopsource.inplace.general}
50585060

5059-
1. The class `inplace_stop_source` models `stoppable_source`. Unlike
5061+
1. The class `inplace_stop_source` models <i>`stoppable-source`</i>. Unlike
50605062
`stop_source`, `inplace_stop_source` does not require dynamic allocation or
50615063
reference counting of a shared stop state. Instead, it requires that all
50625064
uses of associated `inplace_stop_token` and `inplace_stop_callback`
@@ -5164,11 +5166,13 @@ added above, as a new subclause of Stop tokens <b>[thread.stoptoken]</b>.</span>
51645166
template parameter `Callback` that satisfies both `invocable` and
51655167
`destructible`.
51665168

5167-
2. *Remarks:* For a type `C`, if `stoppable_callback_for<Callback, inplace_stop_token,
5168-
C>` is satisfied, then `stoppable_callback_for<Callback,
5169-
inplace_stop_token, C>` is modeled. The exposition-only
5170-
<i>`stop-callback`</i> member is the associated callback function
5171-
([stoptoken.concepts]) of `inplace_stop_callback<Callback>` objects.
5169+
2. *Remarks:* For a type `C`, if
5170+
<code><i>stoppable-callback-for</i>&lt;Callback, inplace_stop_token,
5171+
C></code> is satisfied, then
5172+
<code><i>stoppable-callback-for</i>&lt;Callback, inplace_stop_token,
5173+
C></code> is modeled. The exposition-only <i>`stop-callback`</i> member is
5174+
the associated callback function ([stoptoken.concepts]) of
5175+
`inplace_stop_callback<Callback>` objects.
51725176

51735177
Implementations are not permitted to use additional storage, such
51745178
as dynamic memory, to store the state necessary for an
@@ -6533,30 +6537,27 @@ namespace std::execution {
65336537
template&lt;class Sndr, class Rcvr, class Index>
65346538
requires <i>well-formed</i>&lt;<i>env-type</i>, Index, Sndr, Rcvr>
65356539
struct <i>basic-receiver</i> { // exposition only
6536-
using <i>tag-type</i> = tag_of_t&lt;Sndr>; // exposition only
65376540
using receiver_concept = receiver_t;
65386541

6542+
using <i>tag-type</i> = tag_of_t&lt;Sndr>; // exposition only
6543+
using <i>state-type</i> = <i>state-type</i>&lt;Sndr, Rcvr>; // exposition only
6544+
static constexpr const auto& <i>complete</i> = <i>impls-for</i>&lt;<i>tag-type</i>>::<i>complete</i>; // exposition only
6545+
65396546
template&lt;class... Args>
6540-
requires <i>cpo-callable</i>&lt;<i>impls-for</i>&lt;<i>tag-type</i>>::<i>complete</i>,
6541-
Index, <i>state-type</i>&lt;Sndr, Rcvr>&, Rcvr&, set_value_t, Args...>
6547+
requires <i>cpo-callable</i>&lt;<i>complete</i>, Index, <i>state-type</i>&, Rcvr&, set_value_t, Args...>
65426548
void set_value(Args&&... args) && noexcept {
6543-
(void) <i>impls-for</i>&lt;<i>tag-type</i>>::<i>complete</i>(
6544-
Index(), <i>op</i>-><i>state</i>, <i>op</i>-><i>rcvr</i>, set_value_t(), std::forward&lt;Args>(args)...);
6549+
<i>complete</i>(Index(), <i>op</i>-><i>state</i>, <i>op</i>-><i>rcvr</i>, set_value_t(), std::forward&lt;Args>(args)...);
65456550
}
65466551

65476552
template&lt;class Error>
6548-
requires <i>cpo-callable</i>&lt;<i>impls-for</i>&lt;<i>tag-type</i>>::<i>complete</i>,
6549-
Index, <i>state-type</i>&lt;Sndr, Rcvr>&, Rcvr&, set_error_t, Error>
6553+
requires <i>cpo-callable</i>&lt;<i>complete</i>, Index, <i>state-type</i>&, Rcvr&, set_error_t, Error>
65506554
void set_error(Error&& err) && noexcept {
6551-
(void) <i>impls-for</i>&lt;<i>tag-type</i>>::<i>complete</i>(
6552-
Index(), <i>op</i>-><i>state</i>, <i>op</i>-><i>rcvr</i>, set_error_t(), std::forward&lt;Error>(err));
6555+
<i>complete</i>(Index(), <i>op</i>-><i>state</i>, <i>op</i>-><i>rcvr</i>, set_error_t(), std::forward&lt;Error>(err));
65536556
}
65546557

65556558
void set_stopped() && noexcept
6556-
requires <i>cpo-callable</i>&lt;<i>impls-for</i>&lt;<i>tag-type</i>>::<i>complete</i>,
6557-
Index, <i>state-type</i>&lt;Sndr, Rcvr>&, Rcvr&, set_stopped_t> {
6558-
(void) <i>impls-for</i>&lt;<i>tag-type</i>>::<i>complete</i>(
6559-
Index(), <i>op</i>-><i>state</i>, <i>op</i>-><i>rcvr</i>, set_stopped_t());
6559+
requires <i>cpo-callable</i>&lt;<i>complete</i>, Index, <i>state-type</i>&, Rcvr&, set_stopped_t> {
6560+
<i>complete</i>(Index(), <i>op</i>-><i>state</i>, <i>op</i>-><i>rcvr</i>, set_stopped_t());
65606561
}
65616562

65626563
auto get_env() const noexcept -> <i>env-type</i>&lt;Index, Sndr, Rcvr> {

0 commit comments

Comments
 (0)