From 2b5bb9eee8b3efff6a2f4f70e9831e68fe5c1a89 Mon Sep 17 00:00:00 2001 From: David Eles Date: Tue, 7 Jan 2025 11:22:16 +0100 Subject: [PATCH 1/2] Add test and fix static_thread_pool::get_scheduler_on_thread. nodemask_ is not initialized when get_scheduler_on_thread is called. Test case fails without the fix. --- include/exec/static_thread_pool.hpp | 2 +- test/exec/CMakeLists.txt | 1 + test/exec/test_static_thread_pool.cpp | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/exec/test_static_thread_pool.cpp 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..66eb7f943 --- /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); +} From 1663fc67558a20e57050a18610033135b0b8b971 Mon Sep 17 00:00:00 2001 From: David Eles Date: Tue, 7 Jan 2025 11:47:39 +0100 Subject: [PATCH 2/2] Format new code --- test/exec/test_static_thread_pool.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/exec/test_static_thread_pool.cpp b/test/exec/test_static_thread_pool.cpp index 66eb7f943..57c2f48d4 100644 --- a/test/exec/test_static_thread_pool.cpp +++ b/test/exec/test_static_thread_pool.cpp @@ -6,16 +6,16 @@ #include namespace ex = stdexec; -TEST_CASE("static_thread_pool::get_scheduler_on_thread Test start on a specific thread", "[types][static_thread_pool]") -{ +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}; + exec::static_thread_pool pool{num_of_threads}; std::unordered_set thread_ids; - for(size_t i = 0; i < num_of_threads; ++i) - { + 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::then([&] { thread_ids.insert(std::this_thread::get_id()); }); ex::sync_wait(std::move(sender)); } REQUIRE(thread_ids.size() == num_of_threads);