Skip to content

when_all: Conditional Stop Source#2124

Open
RobertLeahy wants to merge 1 commit into
NVIDIA:mainfrom
RobertLeahy:when_all_20260623
Open

when_all: Conditional Stop Source#2124
RobertLeahy wants to merge 1 commit into
NVIDIA:mainfrom
RobertLeahy:when_all_20260623

Conversation

@RobertLeahy

@RobertLeahy RobertLeahy commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

This commit implements P4217R1 and P4269R0 by making the following changes to when_all:

  • when_all() is now expression-equivalent to just()
  • when_all(s) is now expression-equivalent to auto(s) (i.e. it decay-copies s)
  • The operation state for when_all(s0, ..., sN) now only contains a stop source if:
    • Any of s0, ..., sN can complete unsuccessfully in the ambient environment, or
    • Decay-copying the values sent by any of s0, ... sN can throw an exception

The last bullet prevents when_all from "hallucinating" set_stopped: Previously when_all unconditionally managed a stop source, and injected stop tokens therefrom into its children. Consider when_all(s0, s1) where s0 and s1:

  • Have only set_value_t() as a completion signature in the ambient environment, and
  • Have set_value_t() and set_stopped_t() as completion signatures in an environment with an inplace_stop_token

when_all(s0, s1) plainly does not need a stop source because neither s0 nor s1 will ever complete unsuccessfully (see bullet one above). However when_all(s0, s1) would previously create a stop source anyway, and inject tokens therefrom into s0 and s1. This would cause s0 and s1 to report an additional stopped completion (see bullet two above) which would cause when_all to report set_value_t() and set_stopped_t() as completion signatures even though the latter is never actually emitted (because s0 and s1 don't fail except by stop request, but the only way for a stop request to be emitted is for either of them to fail).

This commit implements P4217R1 and P4269R0 by making the following
changes to when_all:

- when_all() is now expression-equivalent to just()
- when_all(s) is now expression-equivalent to auto(s) (i.e. it decay-
  copies s)
- The operation state for when_all(s0, ..., sN) now only contains a stop
  source if:
  - Any of s0, ..., sN can complete unsuccessfully in the ambient
    environment, or
  - Decay-copying the values sent by any of s0, ... sN can throw an
    exception

The last bullet prevents when_all from "hallucinating" set_stopped:
Previously when_all unconditionally managed a stop source, and injected
stop tokens therefrom into its children. Consider when_all(s0, s1) where
s0 and s1:

- Have only set_value_t() as a completion signature in the ambient
  environment, and
- Have set_value_t() and set_stopped_t() as completion signatures in an
  environment with an inplace_stop_token

when_all(s0, s1) plainly does not need a stop source because neither s0
nor s1 will ever complete unsuccessfully (see bullet one above). However
when_all(s0, s1) would previously create a stop source anyway, and
inject tokens therefrom into s0 and s1. This would cause s0 and s1 to
report an additional stopped completion (see bullet two above) which
would cause when_all to report set_value_t() and set_stopped_t() as
completion signatures even though the latter is never actually emitted
(because s0 and s1 don't fail except by stop request, but the only way
for a stop request to be emitted is for either of them to fail).
@copy-pr-bot

copy-pr-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant