`stop-when`: the fused token's callback can run twice, or be skipped, when the first token is already stopped
I maintainer di solito rispondono entro 1 giorno
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
- Ambito
- backend-api-design
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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di NVIDIA/stdexec
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
NVIDIA/stdexec#1751 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 15/100
NVIDIA/stdexec#2337 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 54/100
I maintainer di solito rispondono entro 1 giorno
-
continues_on: hop opstate not connected with secondary environmentForse già presa @ericniebler l’ha presa 25 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
NVIDIA/stdexec#2268 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
NVIDIA/stdexec#2240 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di NVIDIA/stdexec
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
FriendsofECCE/ECCE#336 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
bitcoin-core/gui-qml#1030 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
tesseract-robotics/tesseract#1384 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
NVIDIA/nccl-extensions#26 ·