Repository navigation
fix(stdexec): initialize stop-when's once-flag before its callbacks - #2332
Merged
ericniebler merged 1 commit intoOct 13, 2026
Merged
ericniebler merged 1 commit into
ericniebler merged 1 commit into
Conversation
The fused token's callback_type declared __called_ after __cb1_ and __cb2_. When the first token is already stopped, __cb1_'s constructor invokes the function immediately, and the function reads and writes __called_ -- whose lifetime has not started: the flag then observes an indeterminate value and is subsequently overwritten with false. The function can therefore run twice (flag read as 0, then reset), or be skipped entirely (flag read as non-zero and the second token never stopped), both of which violate [exec.stop.when]. Regression from NVIDIA#2234. Declare __called_ before the two callback members so that any immediate invocation during construction sees a live, initialized flag. Fixes NVIDIA#2326. test.stdexec passes in Release and Debug with STDEXEC_ENABLE_EXTRA_TYPE_CHECKING on; a regression test covering the already-stopped-first-token case is included.
Contributor
Author
|
/ok to test 9a04fc9 |
ericniebler
approved these changes
Oct 13, 2026
Collaborator
|
/ok to test 9a04fc9 |
Collaborator
|
this is a dupe of #2327, but i'm keeping it for the test. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #2326. This reorders the once-flag
__called_in__stop_when_::__fused_token<T1, T2>::callback_typeso that its lifetime starts before the two inner stop callbacks that use it.Note: PR #2327 fixes the same bug the same way and is approved but unmerged; this PR was prepared independently and introduces a regression test that #2327 does not include.
Problem
callback_typedeclared its once-flag after the two inner callbacks:If the first token is already stopped,
__cb1_'s constructor invokes the function immediately. That function does__called_.exchange(true)on an object whose lifetime has not begun, and then__called_'s own initializer storesfalseover it. Depending on the indeterminate value observed:Both violate [exec.stop.when]: the function must run when either token is stopped, and at most once. Regression from #2234.
Fix
__called_is declared before__cb1_/__cb2_, so any immediate invocation during construction operates on a live, initialized flag:Verification
calls at registration: 1 (expected 1), in total: 2 (expected 1)before this change, and the correct1and1after it.