Skip to content

Commit 3f41dc9

Browse files
committed
execution: continues_on,schedule_from (#1384)
1 parent 302be0f commit 3f41dc9

File tree

7 files changed

+390
-11
lines changed

7 files changed

+390
-11
lines changed

reference/execution/execution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ namespace std::execution {
112112
|------|------|----------------|
113113
| [`execution::sender_adaptor_closure`](execution/sender_adaptor_closure.md.nolink) | Senderアダプタ実装用クロージャ型(class template) | C++26 |
114114
| [`execution::starts_on`](execution/starts_on.md) | 指定Scheduler上で開始する (customization point object) | C++26 |
115-
| [`execution::continues_on`](execution/continues_on.md.nolink) | 指定Scheduler上で継続する (customization point object) | C++26 |
115+
| [`execution::continues_on`](execution/continues_on.md) | 指定Scheduler上で継続する (customization point object) | C++26 |
116116
| [`execution::on`](execution/on.md) | 指定Senderのみ別Scheduler上で実行する (customization point object) | C++26 |
117-
| [`execution::schedule_from`](execution/schedule_from.md.nolink) | Sender完了に依存する作業をスケジュール (customization point object) | C++26 |
117+
| [`execution::schedule_from`](execution/schedule_from.md) | Sender完了に依存する作業をスケジュール (customization point object) | C++26 |
118118
| [`execution::then`](execution/then.md) | 値完了時の継続処理をアタッチ (customization point object) | C++26 |
119119
| [`execution::upon_error`](execution/upon_error.md.nolink) | エラー完了時の継続処理をアタッチ (customization point object) | C++26 |
120120
| [`execution::upon_stopped`](execution/upon_stopped.md.nolink) | 停止完了時の継続処理をアタッチ (customization point object) | C++26 |

reference/execution/execution/child-type.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace std::execution {
2121
- C++26
2222
2323
## 関連項目
24-
- [`execution::schedule_from`](schedule_from.md.nolink)
24+
- [`execution::schedule_from`](schedule_from.md)
2525
- [`execution::into_variant`](into_variant.md)
2626
2727
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# continues_on
2+
* execution[meta header]
3+
* cpo[meta id-type]
4+
* std::execution[meta namespace]
5+
* cpp26[meta cpp]
6+
7+
```cpp
8+
namespace std::execution {
9+
struct continues_on_t { unspecified };
10+
inline constexpr continues_on_t continues_on{};
11+
}
12+
```
13+
* unspecified[italic]
14+
15+
## 概要
16+
`continues_on`は、指定[Scheduler](scheduler.md)上で完了させるSenderアダプタである。
17+
18+
`continues_on`はパイプライン記法をサポートする。
19+
20+
21+
## 効果
22+
説明用の式`sch`と`sndr`に対して、`decltype((sch))`が[`scheduler`](scheduler.md)を満たさない、もしくは`decltype((sndr))`が[`sender`](sender.md)を満たさないとき、呼び出し式`continues_on(sndr, sch)`は不適格となる。
23+
24+
そうでなければ、呼び出し式`continues_on(sndr, sch)`は`sndr`が1回だけ評価されることを除いて、下記と等価。
25+
26+
```cpp
27+
transform_sender(get-domain-early(sndr), make-sender(continues_on, sch, sndr))
28+
```
29+
* transform_sender[link transform_sender.md]
30+
* get-domain-early[link get-domain-early.md]
31+
* make-sender[link make-sender.md]
32+
33+
34+
### Senderアルゴリズムタグ `continues_on`
35+
Senderアルゴリズム動作説明用のクラステンプレート[`impls-for`](impls-for.md)に対して、下記の特殊化が定義される。
36+
37+
```cpp
38+
namespace std::execution {
39+
template<>
40+
struct impls-for<continues_on_t> : default-impls {
41+
static constexpr auto get-attrs =
42+
[](const auto& data, const auto& child) noexcept -> decltype(auto) {
43+
return JOIN-ENV(SCHED-ATTRS(data), FWD-ENV(get_env(child)));
44+
};
45+
};
46+
}
47+
```
48+
* impls-for[link impls-for.md]
49+
* default-impls[link impls-for.md]
50+
* JOIN-ENV[link JOIN-ENV.md.nolink]
51+
* SCHED-ATTRS[link SCHED-ATTRS.md.nolink]
52+
* FWD-ENV[link ../forwarding_query.md]
53+
* get_env[link get_env.md]
54+
55+
説明用の式`sndr`と`env`に対して、型`Sndr`を`decltype((sndr))`とする。[`sender-for`](sender-for.md)`<Sndr, continues_on_t> == false`のとき、式`continues_on.transform_sender(sndr, env)`は不適格となる。
56+
57+
そうでなければ、式`continues_on.transform_sender(sndr, env)`は下記と等価。
58+
59+
```cpp
60+
auto [_, data, child] = sndr;
61+
return schedule_from(std::move(data), std::move(child));
62+
```
63+
* schedule_from[link schedule_from.md]
64+
* std::move[link /reference/utility/move.md]
65+
66+
67+
## カスタマイゼーションポイント
68+
Senderアルゴリズム構築時に、[Sender](sender.md)`sndr`[関連付けられた実行ドメイン](get-domain-early.md)に対して[`execution::transform_sender`](transform_sender.md)経由でSender変換が行われる。
69+
[デフォルト実行ドメイン](../execution/default_domain.md)では無変換。
70+
71+
[Receiver](receiver.md)との[接続(connect)](connect.md)時に、[Scheduler](scheduler.md)`sch`に[関連付けられた実行ドメイン](get-domain-late.md)に対して[`execution::transform_sender`](transform_sender.md)経由でSender変換が行われる。
72+
[デフォルト実行ドメイン](../execution/default_domain.md)では`continues_on.transform_sender(out_sndr, env)`が呼ばれ、[`schedule_from`](schedule_from.md)Senderへと変換される。
73+
74+
説明用の式`out_sndr`を`continues_on(sndr, sch)`の戻り値[Sender](sender.md)とし、型`OutSndr`を`decltype((out_sndr))`とする。式`out_rcvr`を[`sender_in`](sender_in.md)`<OutSndr, Env> == true`となる[環境](../queryable.md)`Env`に関連付けられた[Receiver](receiver.md)とする。`out_sndr`と`out_rcvr`との[接続(connect)](connect.md)結果[Operation State](operation_state.md)への左辺値参照を`op`としたとき、
75+
76+
- 呼び出し[`start`](start.md)`(op)`は、現在の実行エージェント上で入力[Sender](sender.md)`sndr`を開始し、[Scheduler](scheduler.md)`sch`に関連付けられた実行リソースに属する実行エージェント上で`out_rcvr`の完了操作を実行すべき。
77+
- `sch`上でのスケジューリングが失敗した場合、未規定の実行エージェント上で`out_rcvr`の[エラー完了](set_error.md)が行われるべき。
78+
79+
80+
## 備考
81+
`continues_on`Senderアルゴリズムの動作は、[Receiver](receiver.md)[接続(connect)](connect.md)時の[`schedule_from`](schedule_from.md)Senderアルゴリズムへの変換、および説明専用の[`get-domain-late`](get-domain-late.md)関数テンプレートでの特別扱いによって実現される。
82+
83+
84+
## 例
85+
```cpp example
86+
#include <thread>
87+
#include <print>
88+
#include <execution>
89+
namespace ex = std::execution;
90+
91+
92+
int main()
93+
{
94+
std::println("main#{}", std::this_thread::get_id());
95+
96+
ex::run_loop loop;
97+
std::jthread worker{[&]{
98+
std::println("start worker#{}", std::this_thread::get_id());
99+
loop.run();
100+
}};
101+
102+
ex::scheduler auto sch = loop.get_scheduler();
103+
ex::sender auto sndr =
104+
ex::just(2)
105+
| ex::then([](int n) {
106+
std::println("on main#{}", std::this_thread::get_id());
107+
return n * 3;
108+
})
109+
| ex::continues_on(sch)
110+
| ex::then([](int n) {
111+
std::println("on worker#{}", std::this_thread::get_id());
112+
return n * 7;
113+
});
114+
115+
auto [val] = std::this_thread::sync_wait(std::move(sndr)).value();
116+
std::println("val={}", val);
117+
118+
loop.finish();
119+
}
120+
```
121+
* ex::continues_on[color ff0000]
122+
* ex::run_loop[link run_loop.md]
123+
* ex::sender[link sender.md]
124+
* ex::scheduler[link scheduler.md]
125+
* ex::just[link just.md]
126+
* ex::then[link then.md]
127+
* get_scheduler()[link run_loop/get_scheduler.md]
128+
* run()[link run_loop/run.md]
129+
* finish()[link run_loop/finish.md]
130+
* std::this_thread::sync_wait[link ../this_thread/sync_wait.md]
131+
* value()[link /reference/optional/optional/value.md]
132+
* std::move[link /reference/utility/move.md]
133+
* std::this_thread::get_id()[link /reference/thread/this_thread/get_id.md]
134+
135+
### 出力例
136+
```
137+
main#137071308048192
138+
on main#137071308048192
139+
start worker#137071301756480
140+
on worker#137071301756480
141+
val=42
142+
```
143+
144+
145+
## バージョン
146+
### 言語
147+
- C++26
148+
149+
### 処理系
150+
- [Clang](/implementation.md#clang): ??
151+
- [GCC](/implementation.md#gcc): ??
152+
- [ICC](/implementation.md#icc): ??
153+
- [Visual C++](/implementation.md#visual_cpp): ??
154+
155+
156+
## 関連項目
157+
- [`execution::schedule`](schedule.md)
158+
- [`execution::starts_on`](starts_on.md)
159+
- [`execution::on`](on.md)
160+
161+
162+
## 参照
163+
- [P2999R3 Sender Algorithm Customization](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2999r3.html)
164+
- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html)

reference/execution/execution/get-domain-late.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ constexpr auto get-domain-late(const Sndr& sndr, const Env& env) noexcept;
1313
[Sender](sender.md)と[Receiver](receiver.md)間[接続(connect)](connect.md)時のカスタマイゼーションポイントとして、[実行ドメイン](default_domain.md)を取得する説明専用の関数テンプレート。
1414
1515
下記の優先順で実行ドメインを検索し、最初に適格となる型を採用する。
16-
(Senderアルゴリズム[`continue_on`](continue_on.md.nolink)のみ引数に指定した[Scheduler](scheduler.md)から取得。)
16+
(Senderアルゴリズム[`continues_on`](continues_on.md)のみ引数に指定した[Scheduler](scheduler.md)から取得。)
1717
1818
- Senderの[属性](../queryable.md)の実行ドメイン
1919
- Senderの[完了Scheduler](get_completion_scheduler.md)の実行ドメイン
@@ -25,7 +25,7 @@ constexpr auto get-domain-late(const Sndr& sndr, const Env& env) noexcept;
2525
## 効果
2626
説明用の型`Domain`を下記の通り定義したとき、`return Domain();`と等価。
2727
28-
- [`sender-for`](sender-for.md)`<Sndr,` [`continue_on_t`](continue_on.md.nolink)`> == true`のとき、次のラムダ式呼び出し結果の型とする。
28+
- [`sender-for`](sender-for.md)`<Sndr,` [`continues_on_t`](continues_on.md)`> == true`のとき、次のラムダ式呼び出し結果の型とする。
2929
3030
```cpp
3131
[] {
@@ -50,7 +50,7 @@ constexpr auto get-domain-late(const Sndr& sndr, const Env& env) noexcept;
5050
5151
5252
## 備考
53-
Senderアダプタ[`continue_on`](continue_on.md.nolink)は[`schedule_from`](schedule_from.md.nolink)と連動して、実行コンテキスト遷移制御のカスタマイゼーションポイントをSchedulerに提供する。
53+
Senderアダプタ[`continues_on`](continues_on.md)は[`schedule_from`](schedule_from.md)と連携して、実行コンテキスト遷移制御のカスタマイゼーションポイントをSchedulerに提供する。
5454
5555
5656
## バージョン
@@ -60,6 +60,7 @@ Senderアダプタ[`continue_on`](continue_on.md.nolink)は[`schedule_from`](sch
6060
6161
## 関連項目
6262
- [`execution::connect`](connect.md)
63+
- [`execution::continues_on`](continues_on.md)
6364
6465
6566
## 参照

reference/execution/execution/on.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ transform_sender(
121121
```
122122
* scheduler[link scheduler.md]
123123
* get_scheduler[link get_scheduler.md]
124-
* continues_on[link continues_on.md.nolink]
124+
* continues_on[link continues_on.md]
125125
* starts_on[link starts_on.md]
126126
* get_completion_scheduler[link get_completion_scheduler.md]
127127
* set_value_t[link set_value.md]
@@ -323,7 +323,7 @@ val=42
323323
## 関連項目
324324
- [`execution::schedule`](schedule.md)
325325
- [`execution::starts_on`](starts_on.md)
326-
- [`execution::continues_on`](continues_on.md.nolink)
326+
- [`execution::continues_on`](continues_on.md)
327327

328328

329329
## 参照

0 commit comments

Comments
 (0)