ReactivePlusPlus
ReactiveX implementation for C++20
Loading...
Searching...
No Matches
rpp::schedulers::thread_pool Class Referencefinal

Scheduler owning static thread pool of workers and using "some" thread from this pool on create_worker call. More...

#include <thread_pool.hpp>

Public Member Functions

 thread_pool (size_t threads_count=std::thread::hardware_concurrency())
 
rpp::schedulers::worker< worker_strategy > create_worker () const
 

Detailed Description

Scheduler owning static thread pool of workers and using "some" thread from this pool on create_worker call.

Warning
Expected to use this scheduler as local variable to share same threads between different operators or as static variable
Examples
const auto scheduler = rpp::schedulers::thread_pool{4};
rpp::source::just(1, 2, 3, 4, 5, 6, 7, 8)
| rpp::operators::flat_map([scheduler](int value) { return rpp::source::just(scheduler, value)
| rpp::operators::delay(std::chrono::nanoseconds{500}, rpp::schedulers::immediate{}); })
| rpp::operators::subscribe([](int v) { std::cout << "[" << std::this_thread::get_id() << "] " << v << std::endl; });
// Output: (can be in any order but same correlation between thread and values)
// [thread_1] 1
// [thread_2] 2
// [thread_3] 3
// [thread_4] 4
// [thread_1] 5
// [thread_2] 6
// [thread_3] 7
// [thread_4] 8
Examples
thread_pool.cpp.

The documentation for this class was generated from the following file: