32#ifndef THREADPOOL_DEFINITIONS_H
33#define THREADPOOL_DEFINITIONS_H
35#ifdef WOSS_MULTITHREAD
42#include <condition_variable>
59 using Task = std::function< void() >;
95 template <
class F,
class... Args>
96 auto submit(F&& f, Args&&... args) -> std::future<decltype(std::forward<F>(f)(std::forward<Args>(args)...))> {
98 using return_type =
decltype(std::forward<F>(f)(std::forward<Args>(args)...));
104 auto task = std::make_shared< std::packaged_task< return_type() > > (
105 std::bind(std::forward<F>(f), std::forward<Args>(args)...)
109 std::future<return_type> res = task->get_future();
121 tasks.emplace([task]() {
192 task = std::move(
tasks.front());
216 for (std::thread& worker :
workers) {
Definition thread-pool-definitions.h:52
size_t num_threads
Definition thread-pool-definitions.h:144
std::vector< std::thread > workers
Definition thread-pool-definitions.h:148
std::mutex queue_mutex
Definition thread-pool-definitions.h:156
std::condition_variable task_cond_var
Definition thread-pool-definitions.h:160
~ThreadPool()
Definition thread-pool-definitions.h:84
auto submit(F &&f, Args &&... args) -> std::future< decltype(std::forward< F >(f)(std::forward< Args >(args)...))>
Submits a task to the thread pool.
Definition thread-pool-definitions.h:96
std::function< void() > Task
Definition thread-pool-definitions.h:59
size_t getNumThreads()
Gets the number of threads in the pool.
Definition thread-pool-definitions.h:136
void stop()
Definition thread-pool-definitions.h:207
std::queue< Task > tasks
Definition thread-pool-definitions.h:152
void start()
Definition thread-pool-definitions.h:169
ThreadPool(size_t n_threads)
Definition thread-pool-definitions.h:66
bool stop_flag
Definition thread-pool-definitions.h:164
Definition ac-toolbox-arr-asc-reader.h:44