Skip to content

Commit d592785

Browse files
authored
Merge pull request #1465 from DavidElesTheFox/bugfix/static-thread-pool-on-thread-fix
Bug: static_thread_pool::get_scheduler_on_thread causes SegFault
2 parents c1f8c62 + 1663fc6 commit d592785

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

include/exec/static_thread_pool.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ namespace exec {
407407

408408
static_thread_pool_* pool_;
409409
remote_queue* queue_;
410-
const nodemask* nodemask_;
410+
const nodemask* nodemask_ = &nodemask::any();
411411
std::size_t thread_idx_{std::numeric_limits<std::size_t>::max()};
412412

413413
public:

test/exec/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ set(exec_test_sources
4444
test_trampoline_scheduler.cpp
4545
test_sequence_senders.cpp
4646
test_sequence.cpp
47+
test_static_thread_pool.cpp
4748
test_just_from.cpp
4849
sequence/test_any_sequence_of.cpp
4950
sequence/test_empty_sequence.cpp
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "catch2/catch.hpp"
2+
#include <exec/static_thread_pool.hpp>
3+
#include <stdexec/execution.hpp>
4+
5+
#include <thread>
6+
#include <unordered_set>
7+
namespace ex = stdexec;
8+
9+
TEST_CASE(
10+
"static_thread_pool::get_scheduler_on_thread Test start on a specific thread",
11+
"[types][static_thread_pool]") {
12+
constexpr const size_t num_of_threads = 5;
13+
exec::static_thread_pool pool{num_of_threads};
14+
15+
std::unordered_set<std::thread::id> thread_ids;
16+
for (size_t i = 0; i < num_of_threads; ++i) {
17+
auto sender = ex::schedule(pool.get_scheduler_on_thread(i))
18+
| ex::then([&] { thread_ids.insert(std::this_thread::get_id()); });
19+
ex::sync_wait(std::move(sender));
20+
}
21+
REQUIRE(thread_ids.size() == num_of_threads);
22+
}

0 commit comments

Comments
 (0)