16 #ifndef GRPPI_NATIVE_WORKER_POOL_H
17 #define GRPPI_NATIVE_WORKER_POOL_H
37 num_threads_{num_threads},
59 template <typename E, typename F, typename ... Args>
60 void launch(const E & ex, F f, Args && ... args) {
61 workers_.emplace_back([=,&ex]() {
62 auto manager = ex.thread_manager();
67 template <
typename E,
typename F,
typename ... Args>
69 for (
int i=0; i<num_threads_; ++i) {
70 workers_.emplace_back([=,&ex]() {
71 auto manager = ex.thread_manager();
82 for (
auto && w : workers_) { w.join(); }
87 const int num_threads_;
88 std::vector<std::thread> workers_;
Pool of worker threads. This class offers a simple pool of worker threads.
Definition: worker_pool.h:29
worker_pool(worker_pool &&) noexcept=default
void launch(const E &ex, F f, Args &&... args)
Launch a function in the pool.
Definition: worker_pool.h:60
void launch_tasks(const E &ex, F &&f, Args &&... args)
Definition: worker_pool.h:68
~worker_pool() noexcept
Destructs the worker pool after joining with all threads in the pool.
Definition: worker_pool.h:45
worker_pool(int num_threads) noexcept
Creates a worker pool with a number of threads.
Definition: worker_pool.h:36
void wait() noexcept
Wait until all launched tasks have been completed.
Definition: worker_pool.h:81
Definition: callable_traits.h:21