From 9e2f5f1b6dc2a20f496e6859d855cb5fc049d1ce Mon Sep 17 00:00:00 2001 From: Minh Vu Date: Fri, 19 Jun 2026 22:15:15 +0200 Subject: [PATCH] Fix schedule_all empty range completion --- include/exec/static_thread_pool.hpp | 6 ++++++ test/exec/test_static_thread_pool.cpp | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/exec/static_thread_pool.hpp b/include/exec/static_thread_pool.hpp index 5f18060f7..c293fa8db 100644 --- a/include/exec/static_thread_pool.hpp +++ b/include/exec/static_thread_pool.hpp @@ -1746,6 +1746,12 @@ namespace experimental::execution void start() & noexcept { std::size_t size = items_.size(); + if (size == 0) + { + STDEXEC::set_value(static_cast(this->rcvr_)); + return; + } + std::size_t nthreads = this->pool_.available_parallelism(); bwos_params params = this->pool_.params(); std::size_t local_size = params.blockSize * params.numBlocks; diff --git a/test/exec/test_static_thread_pool.cpp b/test/exec/test_static_thread_pool.cpp index 4d38f825e..beb23c6d9 100644 --- a/test/exec/test_static_thread_pool.cpp +++ b/test/exec/test_static_thread_pool.cpp @@ -1,8 +1,10 @@ #include "catch2/catch_all.hpp" +#include #include #include #include +#include #include #include namespace ex = STDEXEC; @@ -45,6 +47,16 @@ TEST_CASE("bulk on static_thread_pool executes on multiple threads", "[types][st REQUIRE(thread_ids.size() == num_of_threads); } +TEST_CASE("schedule_all on static_thread_pool handles empty ranges", + "[types][static_thread_pool]") +{ + exec::static_thread_pool pool{2}; + auto sender = exec::schedule_all(pool, std::views::iota(size_t{0}, size_t{0})) + | exec::ignore_all_values(); + + CHECK(ex::sync_wait(std::move(sender))); +} + TEST_CASE("bulk on static_thread_pool executes on multiple threads, take 2", "[types][static_thread_pool]") {