Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Chiusa
#2,326 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@workingBanana ci sta già lavorando.

Dal 12/10/2026.

  • #2327 di @workingBanana — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
cpp

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C++
Stelle
2.5k
Fork
277
Merge medio
1g 16h
PR unite (30g)
65

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NVIDIA/stdexec

Tutte le issue di NVIDIA/stdexec

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.