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

Abstract class extending basic thread pool implementation to provide a basis layer to handle thread associated resources. More...

#include <ResThreadPool.h>

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

Public Member Functions

 ResThreadPool (std::size_t const _pool_size)
 Resource thread pool constructor. More...
 
template<typename Task >
void run_res_task (Task task)
 Run a task with associated resources when there is an available thread for it.
 
template<typename Task >
bool try_run_res_task (Task task)
 Run a task with associated resources. If there is not even a single available thread, then return false so non-blocking behavior is possible. More...
 
- Public Member Functions inherited from SimpleThreadPool< TaskArgs ... >
 SimpleThreadPool (std::size_t const _pool_size)
 Simple thread pool constructor. More...
 
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 int getAvailableResourceSetIndex () const
 Obtain the index of an available resource set. More...
 
virtual void wrap_res_task (boost::function< void(TaskArgs ...)> &task, int const resourceIdx)
 Wrap a task so that available threads count can be increased once provided task has been completed. More...
 
void do_task (boost::function< void(TaskArgs ...)> &task) override
 Throw exception when calling non resource do_task. More...
 
virtual void do_res_task (boost::function< void(TaskArgs ...)> &task, int const resourceIdx)=0
 Invoke task with associated resources with corresponding arguments. More...
 
- Protected Member Functions inherited from SimpleThreadPool< TaskArgs ... >
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...
 

Protected Attributes

bool * resourceSetAvailable
 Array of flags specifying availability of resource sets. More...
 
- Protected Attributes inherited from SimpleThreadPool< TaskArgs ... >
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 ResThreadPool< TaskArgs >

Abstract class extending basic thread pool implementation to provide a basis layer to handle thread associated resources.

@verison 1.0

See also
ThreadPool

Constructor & Destructor Documentation

◆ ResThreadPool()

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

Resource thread pool constructor.

See also
ThreadPool::ThreadPool(std::size_t const)

Member Function Documentation

◆ do_res_task()

template<typename ... TaskArgs>
virtual void ResThreadPool< TaskArgs >::do_res_task ( boost::function< void(TaskArgs ...)> &  task,
int const  resourceIdx 
)
protectedpure virtual

Invoke task with associated resources with corresponding arguments.

Parameters
taskTask to be invoked
resourceIdxIndex of resources associated with thread invoking the task

◆ do_task()

template<typename ... TaskArgs>
void ResThreadPool< TaskArgs >::do_task ( boost::function< void(TaskArgs ...)> &  task)
inlineoverrideprotectedvirtual

Throw exception when calling non resource do_task.

See also
ThreadPool::do_task

Implements SimpleThreadPool< TaskArgs ... >.

◆ getAvailableResourceSetIndex()

template<typename ... TaskArgs>
virtual int ResThreadPool< TaskArgs >::getAvailableResourceSetIndex ( ) const
inlineprotectedvirtual

Obtain the index of an available resource set.

Returns
Available resource set index

◆ try_run_res_task()

template<typename ... TaskArgs>
template<typename Task >
bool ResThreadPool< TaskArgs >::try_run_res_task ( Task  task)
inline

Run a task with associated resources. If there is not even a single available thread, then return false so non-blocking behavior is possible.

Returns
True if task was posted for asynchronous execution. False if it was not posted because there are not enough available threads to accept it

◆ wrap_res_task()

template<typename ... TaskArgs>
virtual void ResThreadPool< TaskArgs >::wrap_res_task ( boost::function< void(TaskArgs ...)> &  task,
int const  resourceIdx 
)
inlineprotectedvirtual

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

Parameters
taskTask to be wrapped
resourceIdxResource index associated with the task. It is necessary to release associated resources so other tasks can use them later

Member Data Documentation

◆ resourceSetAvailable

template<typename ... TaskArgs>
bool* ResThreadPool< TaskArgs >::resourceSetAvailable
protected

Array of flags specifying availability of resource sets.

The ith element of this array correspond to the ith resource for any resource set/array


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