Skip to content

Allow potentially throwing value copies in thread pool bulk - #2468

Merged
ericniebler merged 1 commit into
NVIDIA:mainfrom
vera-rubin:fix/bulk-throwing-copies
Nov 19, 2026
Merged

ericniebler merged 1 commit into
NVIDIA:mainfrom
vera-rubin:fix/bulk-throwing-copies

Conversation

@vera-rubin

Copy link
Copy Markdown
Contributor

On exec::static_thread_pool, bulk rejects a predecessor that completes with std::vector<int>&, failing with _PREDECESSOR_RESULTS_ARE_NOT_DECAY_COPYABLE_, even when the callback is noexcept:

exec::static_thread_pool pool(2);
std::vector<int> data(4, 0);
auto work = ex::schedule(pool.get_scheduler())
          | ex::then([&]() noexcept -> std::vector<int>& { return data; })
          | ex::bulk(ex::par, 4, [](int i, std::vector<int>& v) noexcept { v[i] = i + 1; });
ex::sync_wait(std::move(work));  // does not compile

The same pipeline compiles with ex::just() in place of the pool sender. exec.bulk only requires the decayed values to be copy constructible, not nothrow copy constructible.

Since #2357 the check is in _get_bulk_sender_cmplsigs_transform in thread_pool_base.hpp. It required __nothrow_decay_copyable, but _bulk_receiver::set_value already catches an exception from storing the values and sends set_error(std::exception_ptr). This PR gates on __decay_copyable and adds set_error(std::exception_ptr) to the completion signatures when the copy can throw. That is the rule windows_thread_pool.hpp already uses, and the bulk_chunked path already accepts throwing copies (see "thread_pool_base bulk stops after value capture fails").

The new test in test_static_thread_pool.cpp checks the vector case end to end, including the exact completion signatures, and checks that a throwing copy is reported through set_error without running the callback, for shapes 0 and 4. Its test file fails to compile without the change. With it, test.exec passes (520 cases) and test.stdexec passes (697 cases) with GCC 13.3, Release. clang-format 21 reports no changes.

`bulk` on `exec::static_thread_pool` (and other pools built on
`thread_pool_base`) rejected predecessors whose values are copyable but
not nothrow-copyable, e.g. `std::vector<int>&`, with
_PREDECESSOR_RESULTS_ARE_NOT_DECAY_COPYABLE_. [exec.bulk] only requires
the decayed values to be copy constructible, and the bulk receiver
already turns an exception from storing them into
set_error(std::exception_ptr).

Require `__decay_copyable` instead of `__nothrow_decay_copyable`, and
advertise set_error(std::exception_ptr) when storing the values can
throw, matching windows_thread_pool.
@copy-pr-bot

copy-pr-bot Bot commented Nov 19, 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.

@ericniebler

Copy link
Copy Markdown
Collaborator

/ok to test 32cac6a

@ericniebler
ericniebler merged commit 89968cb into NVIDIA:main Nov 19, 2026
40 checks passed
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.

2 participants