Skip to content

Commit

Permalink
Merge pull request #1465 from DavidElesTheFox/bugfix/static-thread-po…
Browse files Browse the repository at this point in the history
…ol-on-thread-fix

Bug:  static_thread_pool::get_scheduler_on_thread causes SegFault
  • Loading branch information
ericniebler authored Jan 22, 2025
2 parents c1f8c62 + 1663fc6 commit d592785
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/exec/static_thread_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::size_t>::max()};

public:
Expand Down
1 change: 1 addition & 0 deletions test/exec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions test/exec/test_static_thread_pool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "catch2/catch.hpp"
#include <exec/static_thread_pool.hpp>
#include <stdexec/execution.hpp>

#include <thread>
#include <unordered_set>
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<std::thread::id> 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);
}

0 comments on commit d592785

Please sign in to comment.