diff --git a/include/exec/static_thread_pool.hpp b/include/exec/static_thread_pool.hpp index 132e79ed9..2fb314dd2 100644 --- a/include/exec/static_thread_pool.hpp +++ b/include/exec/static_thread_pool.hpp @@ -407,7 +407,7 @@ namespace exec { static_thread_pool_* pool_; remote_queue* queue_; - const nodemask* nodemask_; + const nodemask* nodemask_ = &nodemask::any(); std::size_t thread_idx_{std::numeric_limits::max()}; public: diff --git a/test/exec/CMakeLists.txt b/test/exec/CMakeLists.txt index 7389f2d64..333270a74 100644 --- a/test/exec/CMakeLists.txt +++ b/test/exec/CMakeLists.txt @@ -44,6 +44,7 @@ set(exec_test_sources test_trampoline_scheduler.cpp test_sequence_senders.cpp test_sequence.cpp + test_static_thread_pool.cpp test_just_from.cpp sequence/test_any_sequence_of.cpp sequence/test_empty_sequence.cpp diff --git a/test/exec/test_static_thread_pool.cpp b/test/exec/test_static_thread_pool.cpp new file mode 100644 index 000000000..57c2f48d4 --- /dev/null +++ b/test/exec/test_static_thread_pool.cpp @@ -0,0 +1,22 @@ +#include "catch2/catch.hpp" +#include +#include + +#include +#include +namespace ex = stdexec; + +TEST_CASE( + "static_thread_pool::get_scheduler_on_thread Test start on a specific thread", + "[types][static_thread_pool]") { + constexpr const size_t num_of_threads = 5; + exec::static_thread_pool pool{num_of_threads}; + + std::unordered_set thread_ids; + for (size_t i = 0; i < num_of_threads; ++i) { + auto sender = ex::schedule(pool.get_scheduler_on_thread(i)) + | ex::then([&] { thread_ids.insert(std::this_thread::get_id()); }); + ex::sync_wait(std::move(sender)); + } + REQUIRE(thread_ids.size() == num_of_threads); +}