Helios++
Helios software for LiDAR simulations
SimpleThreadPool< TaskArgs > Class Template Referenceabstract

Abstract class providing implementation of a simple thread pool which assigns tasks to threads. More...

#include <SimpleThreadPool.h>

Inheritance diagram for SimpleThreadPool< TaskArgs >:
Collaboration diagram for SimpleThreadPool< TaskArgs >:

Public Member Functions

 SimpleThreadPool (std::size_t const _pool_size)
 Simple thread pool constructor. More...
 
template<typename Task >
void run_task (Task task)
 Run a task when there is an available thread for it.
 
virtual void join ()
 Lock until all pending threads have finished.
 
virtual void notifyOne ()
 Notify the conditional variable so if there is a waiting thread it will wake up.
 
- Public Member Functions inherited from ThreadPool
 ThreadPool (std::size_t const _pool_size)
 Thread pool constructor. More...
 
virtual std::size_t getPoolSize () const
 Obtain the thread pool size. More...
 

Protected Member Functions

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. More...
 
virtual void do_task (boost::function< void(TaskArgs ...)> &task)=0
 Invoke task with corresponding arguments. More...
 

Protected Attributes

std::size_t available_
 Number of available threads, those which are not currently performing a task.
 
boost::mutex mutex_
 Mutex to handle concurrent tasks.
 
boost::condition_variable cond_
 Condition variable to handle tasks dispatching depending on available threads.
 
boost::asio::io_service io_service_
 Instance of boost input/output service for asynchronous data processing.
 
std::size_t pool_size
 Size of thread pool (number of threads)
 
- Protected Attributes inherited from ThreadPool
boost::asio::io_service io_service_
 Instance of boost input/output service for asynchronous data processing.
 
boost::asio::executor_work_guard< boost::asio::io_service::executor_type > work_
 Instance of work guard to report the io service when it has pending tasks. More...
 
std::size_t pool_size
 Size of thread pool (number of threads)
 
boost::thread_group threads_
 Group of threads.
 

Detailed Description

template<typename ... TaskArgs>
class SimpleThreadPool< TaskArgs >

Abstract class providing implementation of a simple thread pool which assigns tasks to threads.

Version
1.0
Template Parameters
TaskArgsThe arguments for the task functor

Constructor & Destructor Documentation

◆ SimpleThreadPool()

template<typename ... TaskArgs>
SimpleThreadPool< TaskArgs >::SimpleThreadPool ( std::size_t const  _pool_size)
inlineexplicit

Simple thread pool constructor.

See also
ThreadPool::pool_size
ThreadPool::ThreadPool

Member Function Documentation

◆ do_task()

template<typename ... TaskArgs>
virtual void SimpleThreadPool< TaskArgs >::do_task ( boost::function< void(TaskArgs ...)> &  task)
protectedpure virtual

◆ wrap_task()

template<typename ... TaskArgs>
virtual void SimpleThreadPool< TaskArgs >::wrap_task ( boost::function< void(TaskArgs ...)> &  task)
inlineprotectedvirtual

Wrap a task so that available threads count can be increased once provided task has been completed.

Parameters
taskTask to be wrapped

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