Clarifying the exception specification for bulk callback functions
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 2.4k
- Forks
- 270
- Avg merge
- 3d 6h
- Merged PRs (30d)
- 39
Description
Do we really allow the bulk callback function to throw an exception? That is, when the bulk callback throws an exception, will that exception be propagated through the receiver's set_error(std::exception_ptr)?
Consider:
Given a scheduler sch, what should be the behavior of the following code?
try {
stdexec::sync_wait(stdexec::schedule(sch) | stdexec::bulk(std::execution::par, 1uz, [](std::size_t){
throw std::runtime_error{"xxx"};
}));
}
catch (const std::runtime_error& e) {
...
}
Can the try-catch here catch this std::runtime_error?
For the default implementation of bulk, the answer is yes, it can be caught. But for some customized bulk implementations, it may be different. For example, if sch here is a stdexec::parallel_scheduler, the program will terminate, see https://github.com/NVIDIA/stdexec/blob/e8c349f3f3425b9341306bc56615fc5279a15cf4/include/stdexec/__detail/__parallel_scheduler.hpp#L390-L419
which does not handle the case where the call to __state->__fun_ throws an exception. However, fixing this seems a bit tricky, or should we reconsider the exception specification of bulk_item_receiver_proxy::execute?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read include/stdexec/__detail/__parallel_scheduler.hpp at lines 390-419 and compare the parallel scheduler's callback handling with the default bulk implementation. Use the provided sync_wait/bulk example to establish whether std::runtime_error should reach the receiver's set_error and the surrounding catch; done means the exception contract for customized bulk implementations is decided and verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100