`stop-when`: the fused token's callback can run twice, or be skipped, when the first token is already stopped
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- cpp
調査の方向性
The issue identifies __stop_when_::__fused_token<T1, T2>::callback_type and gives a reproducer using stdexec/execution.hpp. Read the callback member declarations and constructor initialization order, then run the reproducer to check immediate invocation when the first token is already stopped. Done means the callback runs once at registration and is not called again when the second token stops. Pull request #2327 is already open against this issue.
索引モデルが issue の本文から書いたものです。
説明
Summary
__stop_when_::__fused_token<T1, T2>::callback_type declares its once-flag __called_ after the two inner callbacks:
_Fn __fn_;
__cb1_t __cb1_;
__cb2_t __cb2_;
__std::atomic<bool> __called_{false}; // initialized last
If the first token is already stopped, __cb1_'s constructor invokes the callback immediately. That callback does __called_.exchange(true) on an object whose lifetime hasn't started yet. Then __called_'s initializer stores false. So the result depends on the indeterminate value:
- if it was 0: the function runs at registration, the flag is reset, and the function runs a second time when the second token is stopped;
- if it was non-zero: the function is skipped at registration. It runs only if the second token is stopped later, and is lost otherwise.
Both violate [exec.stop.when]: the callback must be invoked when either token is stopped, and at most once.
Introduced in https://github.com/NVIDIA/stdexec/pull/2234
Reproducer
#include <stdexec/execution.hpp>
#include <cstdio>
namespace ex = STDEXEC;
int main() {
ex::inplace_stop_source a, b;
a.request_stop(); // the sender's token is already stopped
int calls = 0, at_registration = -1;
auto probe = ex::read_env(ex::get_stop_token) | ex::then([&](auto token) {
auto fn = [&]() noexcept { ++calls; };
ex::stop_callback_for_t<decltype(token), decltype(fn)> cb(token, fn); // must run: a is stopped
at_registration = calls;
b.request_stop(); // must not run again
});
// The inner stop-when sees a stoppable receiver token (b), so its child gets a fused token.
ex::sync_wait(ex::__stop_when(ex::__stop_when(probe, a.get_token()), b.get_token()));
std::printf("calls at registration: %d (expected 1), in total: %d (expected 1)\n",
at_registration, calls);
return at_registration == 1 && calls == 1 ? 0 : 1;
}
Then output will be: calls at registration: 1 (expected 1), in total: 2 (expected 1). It should be 1 and 1.
- 主要言語
- C++
- スター
- 2.5k
- フォーク
- 276
- 平均マージ
- 1日 13時間
- マージ済み PR(30日)
- 62
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
NVIDIA/stdexec のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
NVIDIA/stdexec#1751 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
`timed_thread_context`: an operation stopped just before the context is destroyed never completes対応中かも @workingBanana が 1 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 20/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 54/100
メンテナーはふだん 1 日以内に返信
-
continues_on: hop opstate not connected with secondary environment対応中かも @ericniebler が 24 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
NVIDIA/stdexec#2268 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
NVIDIA/stdexec#2240 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
Ctrl-C can abort a node: the state timer asks for the node names after shutdown対応中かも @fmrico が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
fmrico/cascade_lifecycle#24 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
Deltakit/deltakit-stim#52 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信