P3941R2 — Scheduler Affinity (14 items) Concurrency Working Group (SG1), Library Evolution Working Group (LEWG), Library Working Group (LWG)
Dietmar Kühl
This paper addresses concerns about the affine_on algorithm used by std::execution::task to ensure coroutines resume on the same scheduler after co_await. The key changes proposed are: removing the scheduler parameter from affine_on so it obtains the scheduler from the receiver's environment via get_scheduler (or a new get_start_scheduler query), requiring that schedulers used with affine_on be infallible (only completing with set_value when given an unstoppable stop token), adding a customization mechanism allowing child senders to opt out of rescheduling, and removing change_coroutine_scheduler due to its problematic semantics.

References — Anthropic Citations API

[1]
"The gist of this proposal is impose constraints on `affine_on`"
[2]
"P3718r0 proposed to add this exact requirement to [exec.get.scheduler] which is no moved to this proposal."
[3]
"P3718r0 proposed to add this exact requirement and P3718r0 proposed that `get_scheduler` should be required"
[4]
"if it obtained an operation state `os` from `connect(scheduler(sch), rcvr)`"
[5]
"it can provide a `never_stoptoken` and this scheduler won't complete with `set_stopped()`"
[6]
"`affine_on` can still guarantee that execution resumes on the expect execution agent"
[7]
"clarifies that the scheduling operation used be `affine_on` needs to be always successful."
[8]
"the inherent cost of having the possibility of having `change_routine_scheduler` can't be removed later"
[9]
"[](const auto&`~~`data`~~`], const auto& child) noexcept -> decltype(auto)"
[10]
"[](const auto&`~~`data`~~`], const auto& child) noexcept -> decltype(auto)"
[11]
"if constexpr (requires(const child_tag_t& t){ t.affine_on(child, ev); }) / return t.affine_on(child, ev);"
[12]
"if constexpr (requires(const child_tag_t& t){ t.affine_on(child, ev); }) / return t.affine_on(child, ev);"
[13]
"The `get_scheduler` query is used to get a scheduler to schedule new work on. and The `get_scheduler` query is used to get the scheduler an operation was `start`ed on."
[14]
"(LWG; the proposed resolution in this issue is incomplete)"
Summary: P3941R2 proposes an affine_on sender adaptor that constrains where a sender's completion runs, ensuring execution resumes on the scheduler associated with the sender rather than allowing arbitrary migration. It also addresses related changes to get_start_scheduler, infallible scheduler requirements, and coroutine scheduler integration.
Pipeline: Discovery (Anthropic Opus + Citations API) → Verification Gate (OpenRouter Opus) → Report Writer (OpenRouter Opus)
Provenance: All references are machine-verified character positions from the Anthropic Citations API — deterministic, exact substrings, not model-generated quotes.