Skip to content

Commit 7a7c220

Browse files
committed
execution: run_loop/get_scheduler (#1384)
1 parent 3181330 commit 7a7c220

10 files changed

Lines changed: 323 additions & 6 deletions

File tree

reference/execution/execution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Senderコンシューマは名前空間 `std::this_thread` で定義される。
145145
| [`execution::completion_signatures`](execution/completion_signatures.md) | 完了シグネチャ集合を表現する型 (class template) | C++26 |
146146
| [`execution::transform_completion_signatures`](execution/transform_completion_signatures.md.nolink) | 完了シグネチャを変換 (alias template) | C++26 |
147147
| [`execution::transform_completion_signatures_of`](execution/transform_completion_signatures_of.md.nolink) | 完了シグネチャを変換 (alias template) | C++26 |
148-
| [`execution::run_loop`](execution/run_loop.md.nolink) | 実行ループ (class) | C++26 |
148+
| [`execution::run_loop`](execution/run_loop.md) | 単一スレッド上でのループ実行 (class) | C++26 |
149149
150150
### コルーチンユーティリティ
151151

reference/execution/execution/get_completion_scheduler.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int main()
7676
}
7777
```
7878
* ex::get_completion_scheduler[color ff0000]
79-
* ex::run_loop[link run_loop.md.nolink]
79+
* ex::run_loop[link run_loop.md]
8080
* ex::scheduler[link scheduler.md]
8181
* ex::sender[link sender.md]
8282
* ex::schedule[link schedule.md]
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# run_loop
2+
* execution[meta header]
3+
* class[meta id-type]
4+
* std::execution[meta namespace]
5+
* cpp26[meta cpp]
6+
7+
```cpp
8+
namespace std::execition {
9+
class run_loop;
10+
}
11+
```
12+
13+
## 概要
14+
`run_loop`は、実行制御ライブラリの作業を[スケジュール](schedule.md)可能な実行リソース(execution resource)である。
15+
16+
内部的にスレッドセーフなFIFO (first-in first-out) 作業キューを保持する。
17+
[`run`メンバ関数](run_loop/run.md.nolink)はキューから作業を取り出し、同関数を呼び出したスレッド上のループで実行する。
18+
19+
`run_loop`インスタンスの動作説明のため、下記の説明用メンバ変数を持つ。
20+
21+
- `count` : FIFOキューが保持する作業の個数
22+
- `state` : 開始(starting)/実行中(running)/完了中(finishing)/完了済み(finished) いずれかのインスタンス状態
23+
24+
25+
## メンバ関数
26+
27+
| 名前 | 説明 | 対応バージョン |
28+
|------|------|-------|
29+
| [`(constructor)`](run_loop/op_constructor.md) | コンストラクタ | C++26 |
30+
| [`(destructor)`](run_loop/op_destructor.md) | デストラクタ | C++26 |
31+
| [`get_scheduler`](run_loop/get_scheduler.md) | Scheduler取得 | C++26 |
32+
| [`run`](run_loop/run.md.nolink) | ループ実行を開始 | C++26 |
33+
| [`finish`](run_loop/finish.md.nolink) | ループ実行を終了 | C++26 |
34+
35+
## 説明専用のメンバ型
36+
37+
| 名前 | 説明 | 対応バージョン |
38+
|------|------|-------|
39+
| [`run-loop-scheduler`](run_loop/run-loop-scheduler.md) | 説明専用クラス | C++26 |
40+
| [`run-loop-sender`](run_loop/run-loop-sender.md) | 説明専用クラス | C++26 |
41+
| [`run-loop-opstate`](run_loop/run-loop-opstate.md.nolink) | 説明専用クラス | C++26 |
42+
43+
44+
## 例
45+
```cpp example
46+
#include <execution>
47+
namespace ex = std::execution;
48+
49+
struct MyReceiver {
50+
using receiver_concept = ex::receiver_t;
51+
52+
void set_value() noexcept
53+
{ std::println("value"); }
54+
void set_error(std::exception_ptr) noexcept
55+
{ std::println("error"); }
56+
void set_stopped() noexcept
57+
{ std::println("stopped"); }
58+
};
59+
60+
61+
int main()
62+
{
63+
// run_loopのスケジュールSenderを取得
64+
ex::run_loop loop;
65+
ex::scheduler auto sch = loop.get_scheduler();
66+
// state:開始(starting)
67+
68+
ex::sender auto sndr = ex::schedule(sch);
69+
ex::receiver auto rcvr = MyReceiver{};
70+
ex::operation_state auto op = ex::connect(sndr, rcvr);
71+
// キューに作業を1つ追加
72+
ex::start(op);
73+
74+
// stateを完了中(finished)へ遷移
75+
loop.finish();
76+
77+
// キュー上の作業を全て処理
78+
loop.run();
79+
// state:完了済み(finished)
80+
}
81+
```
82+
* ex::run_loop[color ff0000]
83+
* ex::scheduler[link scheduler.md]
84+
* ex::sender[link sender.md]
85+
* ex::schedule[link schedule.md]
86+
* ex::receiver[link receiver.md]
87+
* ex::receiver_t[link receiver.md]
88+
* ex::operation_state[link operation_state.md]
89+
* ex::connect[link connect.md]
90+
* ex::start[link start.md]
91+
* get_scheduler()[link run_loop/get_scheduler.md]
92+
* finish()[link run_loop/finish.md.nolink]
93+
* run()[link run_loop/run.md.nolink]
94+
95+
### 出力
96+
```
97+
value
98+
```
99+
100+
101+
## バージョン
102+
### 言語
103+
- C++26
104+
105+
### 処理系
106+
- [Clang](/implementation.md#clang): ??
107+
- [GCC](/implementation.md#gcc): ??
108+
- [ICC](/implementation.md#icc): ??
109+
- [Visual C++](/implementation.md#visual_cpp): ??
110+
111+
112+
## 関連項目
113+
- [`execution::schedule`](schedule.md)
114+
115+
116+
## 参照
117+
- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# get_scheduler
2+
* execution[meta header]
3+
* std::execution[meta namespace]
4+
* run_loop[meta class]
5+
* function[meta id-type]
6+
* cpp26[meta cpp]
7+
8+
```cpp
9+
run-loop-scheduler get_scheduler();
10+
```
11+
* run-loop-scheduler[link run-loop-scheduler.md]
12+
13+
## 概要
14+
`run_loop`上で実行する[Scheduler](../scheduler.md)を返す。
15+
16+
17+
## 戻り値
18+
`run_loop`インスタンス上で作業を[スケジュール](../schedule.md)する[`run-loop-scheduler`](run-loop-scheduler.md)インスタンスを返す。
19+
20+
21+
##
22+
```cpp example
23+
#include <execution>
24+
namespace ex = std::execution;
25+
26+
int main()
27+
{
28+
ex::run_loop loop;
29+
ex::scheduler auto sch = loop.get_scheduler();
30+
}
31+
```
32+
* get_scheduler()[color ff0000]
33+
* ex::run_loop[link ../run_loop.md]
34+
* ex::scheduler[link ../scheduler.md]
35+
36+
### 出力
37+
```
38+
```
39+
40+
## バージョン
41+
### 言語
42+
- C++26
43+
44+
45+
### 処理系
46+
- [Clang](/implementation.md#clang): ??
47+
- [GCC](/implementation.md#gcc): ??
48+
- [ICC](/implementation.md#icc): ??
49+
- [Visual C++](/implementation.md#visual_cpp): ??
50+
51+
52+
## 関連項目
53+
- [`run-loop-scheduler`](run-loop-scheduler.md)
54+
- [`execution::schedule`](../schedule.md)
55+
56+
57+
## 参照
58+
- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# コンストラクタ
2+
* execution[meta header]
3+
* std::execution[meta namespace]
4+
* run_loop[meta class]
5+
* function[meta id-type]
6+
* cpp26[meta cpp]
7+
8+
```cpp
9+
run_loop() noexcept; // (1)
10+
run_loop(run_loop&&) = delete; // (2)
11+
```
12+
13+
## 概要
14+
- (1) : デフォルトコンストラクタ
15+
- (2) : コピー/ムーブ構築の禁止
16+
17+
18+
## 事後条件
19+
(1) : [`run_loop`](../run_loop.md)の説明専用メンバ変数が次の通り初期化される。
20+
21+
- `count` : 値`0`
22+
- `state` : 開始(starting)
23+
24+
25+
## 例外
26+
投げない
27+
28+
29+
## バージョン
30+
### 言語
31+
- C++26
32+
33+
34+
### 処理系
35+
- [Clang](/implementation.md#clang): ??
36+
- [GCC](/implementation.md#gcc): ??
37+
- [ICC](/implementation.md#icc): ??
38+
- [Visual C++](/implementation.md#visual_cpp): ??
39+
40+
41+
## 参照
42+
- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# デストラクタ
2+
* execution[meta header]
3+
* std::execution[meta namespace]
4+
* run_loop[meta class]
5+
* function[meta id-type]
6+
* cpp26[meta cpp]
7+
8+
```cpp
9+
~run_loop();
10+
```
11+
12+
## 概要
13+
`run_loopオブジェクトを破棄する。
14+
15+
16+
## 効果
17+
`count`が非`0`かつ`state`が実行中(running)のとき、[`terminate`](/reference/exception/terminate.md)を呼び出す。
18+
それ以外のときは、効果を持たない。
19+
20+
21+
## バージョン
22+
### 言語
23+
- C++26
24+
25+
26+
### 処理系
27+
- [Clang](/implementation.md#clang): ??
28+
- [GCC](/implementation.md#gcc): ??
29+
- [ICC](/implementation.md#icc): ??
30+
- [Visual C++](/implementation.md#visual_cpp): ??
31+
32+
33+
## 参照
34+
- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# run-loop-scheduler
2+
* execution[meta header]
3+
* std::execution[meta namespace]
4+
* run_loop[meta class]
5+
* class[meta id-type]
6+
* cpp26[meta cpp]
7+
8+
```cpp
9+
class run-loop-scheduler; // exposition only
10+
```
11+
12+
## 概要
13+
`run-loop-scheduler`は、[`get_scheduler`メンバ関数](get_scheduler.md)の戻り値型として利用される説明専用のクラスである。
14+
15+
- `run-loop-scheduler`型は[`scheduler`](../scheduler.md)のモデルとなる未規定の型。
16+
- `run-loop-scheduler`インスタンスは、同インスタンスを取得した[`run_loop`](../run_loop.md)インスタンスの生存期間(lifetime)終了まで有効。
17+
- 2個の`run-loop-scheduler`インスタンスは、[`run_loop`](../run_loop.md)インスタンスから取得された場合に限って等しい。
18+
- 説明用の式`sch`の型が`run-loop-scheduler`であるとき、式[`schedule`](../schedule.md)`(sch)`は型[`run-loop-sender`](run-loop-sender.md)となり、式`sch`が潜在的に例外送出しない(not potentially-throwing)ならばそれに従う。
19+
20+
21+
## バージョン
22+
### 言語
23+
- C++26
24+
25+
26+
## 関連項目
27+
- [`get_scheduler`](get_scheduler.md)
28+
- [`execution::scheduler`](../scheduler.md)
29+
30+
31+
## 参照
32+
- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# run-loop-sender
2+
* execution[meta header]
3+
* std::execution[meta namespace]
4+
* run_loop[meta class]
5+
* class[meta id-type]
6+
* cpp26[meta cpp]
7+
8+
```cpp
9+
class run-loop-sender; // exposition only
10+
```
11+
12+
## 概要
13+
`run-loop-sender`は、[`get_scheduler`メンバ関数](get_scheduler.md)が返す[`run-loop-scheduler`](run-loop-scheduler.md)動作仕様の説明で利用される説明専用のクラスである。
14+
15+
- `run-loop-sender`型は[`sender`](../sender.md)のモデルである。
16+
- 任意の型`Env`に対して、[`completion_signatures_of_t`](../completion_signatures_of_t.md)`<run-loop-sender, Env>`は[`completion_signatures`](../completion_signatures.md)`<`[`set_value_t`](../set_value.md)`(),` [`set_error_t`](../set_error.md)`(`[`exception_ptr`](/reference/exception/exception_ptr.md)`),` [`set_stopped_t`](../set_stopped.md)`()>`
17+
- `run-loop-sender`インスタンスは、関連付けられた[`run_loop`](../run_loop.md)インスタンスの生存期間(lifetime)終了まで有効。
18+
- 説明用の式`sndr`の型を`run-loop-sender`、`CS`が上記[`completion_signatures`](../completion_signatures.md)の特殊化であるとき[`receiver_of`](../receiver_of.md)`<decltype((rcvr)), CS>`が`true`となる式`rcvr`としたとき、
19+
- 式[`connect`](../connect.md)`(sndr, rcvr)`の型は[`run-loop-opstate`](run-loop-opstate.md.nolink)`<`[`decay_t`](/reference/type_traits/decay.md)`<decltype((rcvr))>>`であり、潜在的な例外送出(potentially-throwing)は式`(void(sndr), auto(rcvr))`に従う。
20+
- 完了タグ`C`を[`set_value_t`](../set_value.md)または[`set_stopped_t`](../set_stopped.md)としたとき、式[`get_completion_scheduler`](../get_completion_scheduler.md)`<C>(`[`get_env`](../get_env.md)`(sndr))`の潜在的な例外送出は`sndr`に従う。式の型は[`run-loop-scheduler`](run-loop-scheduler.md)となり、そのインスタンスは同一`sndr`から取得された場合に等しくなる。
21+
22+
23+
## バージョン
24+
### 言語
25+
- C++26
26+
27+
28+
## 関連項目
29+
- [`run-loop-scheduler`](run-loop-scheduler.md)
30+
- [`execution::sender`](../sender.md)
31+
32+
33+
## 参照
34+
- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html)

reference/execution/execution/schedule.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ int main()
6464
* ex::scheduler[link scheduler.md]
6565
* ex::sender[link sender.md]
6666
* ex::then[link then.md.nolink]
67-
* ex::run_loop[link run_loop.md.nolink]
68-
* get_scheduler()[link run_loop/get_scheduler.md.nolink]
67+
* ex::run_loop[link run_loop.md]
68+
* get_scheduler()[link run_loop/get_scheduler.md]
6969
* run()[link run_loop/run.md.nolink]
7070
* finish()[link run_loop/finish.md.nolink]
7171
* std::move[link /reference/utility/move.md]

reference/execution/execution/scheduler.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ int main()
9292
}
9393
```
9494
* ex::scheduler[color ff0000]
95-
* ex::run_loop[link run_loop.md.nolink]
96-
* get_scheduler()[link run_loop/get_scheduler.md.nolink]
95+
* ex::run_loop[link run_loop.md]
96+
* get_scheduler()[link run_loop/get_scheduler.md]
9797

9898
### 出力
9999
```

0 commit comments

Comments
 (0)