Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/exec/static_thread_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,8 @@ namespace experimental::execution
{
thread_local std::uint64_t start_index{std::uint64_t(std::random_device{}())};
start_index += 1;
std::size_t target_index = start_index % thread_count_;
std::size_t n_threads = num_threads(constraints);
std::size_t const n_threads = num_threads(constraints);
std::size_t target_index = start_index % (n_threads == 0 ? thread_count_ : n_threads);
if (n_threads != 0)
{
for (std::size_t node_index = 0; node_index < numa_.num_nodes(); ++node_index)
Expand Down
47 changes: 47 additions & 0 deletions test/exec/test_static_thread_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,35 @@ namespace ex = STDEXEC;

namespace
{
thread_local int current_numa_node = -1;

struct two_node_numa_policy
{
[[nodiscard]]
constexpr auto num_nodes() const noexcept -> std::size_t
{
return 2;
}

[[nodiscard]]
constexpr auto num_cpus(int) const noexcept -> std::size_t
{
return 2;
}

auto bind_to_node(int node) const noexcept -> int
{
current_numa_node = node;
return 0;
}

[[nodiscard]]
constexpr auto thread_index_to_node(std::size_t index) const noexcept -> int
{
return index < 2 ? 1 : 0;
}
};

#if !STDEXEC_NO_STDCPP_EXCEPTIONS()
struct throwing_set_next_receiver
{
Expand Down Expand Up @@ -69,6 +98,24 @@ namespace
#endif
} // namespace

TEST_CASE("constrained static_thread_pool scheduler selects eligible workers",
"[types][static_thread_pool]")
{
constexpr std::size_t const num_of_threads = 4;
exec::static_thread_pool pool{num_of_threads, {}, exec::numa_policy{two_node_numa_policy{}}};
exec::nodemask constraints{};
constraints.set(0);
auto scheduler = pool.get_constrained_scheduler(&constraints);

for (std::size_t i = 0; i < num_of_threads; ++i)
{
auto [node] = ex::sync_wait(ex::schedule(scheduler)
| ex::then([]() noexcept { return current_numa_node; }))
.value();
CHECK(node == 0);
}
}

TEST_CASE("static_thread_pool::get_scheduler_on_thread Test start on a specific thread",
"[types][static_thread_pool]")
{
Expand Down
Loading