Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

`stop-when`: the fused token's callback can run twice, or be skipped, when the first token is already stopped

クローズ
#2,326 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@workingBanana がすでに取り組んでいます。

2026年10月12日 から。

  • #2327 @workingBanana による — オープン

評価

難易度
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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

NVIDIA/stdexec のほかの issue

NVIDIA/stdexec の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。