3 #include <ThreadPool.h>
11 template <
typename ... TaskArgs>
31 boost::condition_variable
cond_;
52 template <
typename Task>
54 boost::unique_lock<boost::mutex> lock(
mutex_);
72 boost::function<
void(TaskArgs ...)>(task)
81 boost::unique_lock<boost::mutex> lock(
mutex_);
94 boost::function<
void(TaskArgs ...)> &task
101 catch (
const std::exception &e) {
102 std::stringstream ss;
103 ss <<
"ThreadPool::wrap_task EXCEPTION: " << e.what();
104 logging::WARN(ss.str());
108 boost::unique_lock<boost::mutex> lock(
mutex_);
119 boost::function<
void(TaskArgs ...)> &task
Abstract class providing implementation of a simple thread pool which assigns tasks to threads.
Definition: SimpleThreadPool.h:12
std::size_t pool_size
Size of thread pool (number of threads)
Definition: ThreadPool.h:47
boost::mutex mutex_
Mutex to handle concurrent tasks.
Definition: SimpleThreadPool.h:26
virtual void do_task(boost::function< void(TaskArgs ...)> &task)=0
Invoke task with corresponding arguments.
boost::asio::io_service io_service_
Instance of boost input/output service for asynchronous data processing.
Definition: ThreadPool.h:36
boost::condition_variable cond_
Condition variable to handle tasks dispatching depending on available threads.
Definition: SimpleThreadPool.h:31
SimpleThreadPool(std::size_t const _pool_size)
Simple thread pool constructor.
Definition: SimpleThreadPool.h:41
virtual void join()
Lock until all pending threads have finished.
Definition: SimpleThreadPool.h:80
virtual void wrap_task(boost::function< void(TaskArgs ...)> &task)
Wrap a task so that available threads count can be increased once provided task has been completed.
Definition: SimpleThreadPool.h:93
virtual void notifyOne()
Notify the conditional variable so if there is a waiting thread it will wake up.
Definition: SimpleThreadPool.h:129
std::size_t available_
Number of available threads, those which are not currently performing a task.
Definition: SimpleThreadPool.h:22
void run_task(Task task)
Run a task when there is an available thread for it.
Definition: SimpleThreadPool.h:53
Base class providing core implementation of a thread pool to deal with multi threading tasks.
Definition: ThreadPool.h:28
std::size_t pool_size
Size of thread pool (number of threads)
Definition: ThreadPool.h:47
boost::asio::io_service io_service_
Instance of boost input/output service for asynchronous data processing.
Definition: ThreadPool.h:36