Helios++
Helios software for LiDAR simulations
thread_pool Class Reference

Class representing a thread pool to deal with multi threading tasks. More...

#include <ThreadPool.h>

Collaboration diagram for thread_pool:

Public Member Functions

 thread_pool (std::size_t _pool_size, double deviceAccuracy)
 Thread pool constructor. More...
 
std::size_t getPoolSize ()
 Obtain the thread pool size. More...
 
template<typename Task >
void run_task (Task task)
 Run a task when there is an available thread for it.
 
void join ()
 Lock until all pending threads have finished.
 

Private Member Functions

int getAvailableResourceSetIndex ()
 Obtain the index of an available resource set. More...
 
void wrap_task (boost::function< void(std::vector< std::vector< double >> &, RandomnessGenerator< double > &, RandomnessGenerator< double > &, NoiseSource< double > &)> &task, int resourceIdx)
 Wrap a task so that available threads count can be increased once provided task has been completed. More...
 

Private Attributes

boost::asio::io_service io_service_
 Instance of boost input/output service for asynchronous data processing.
 
boost::asio::io_service::work work_
 Instance of work 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.
 
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 var to handle tasks dispatching depending on available threads.
 
std::vector< std::vector< double > > * apMatrices
 
RandomnessGenerator< double > * randGens
 First randomness generators (general purpose), one per thread.
 
RandomnessGenerator< double > * randGens2
 Second randomness generators (to substitute old box muller), one per thread.
 
UniformNoiseSource< double > * intersectionHandlingNoiseSources
 Intersection handling noise sources, one per thread.
 
bool * resourceSetAvailable
 Array of flags specifying availability of resource sets. More...
 

Detailed Description

Class representing a thread pool to deal with multi threading tasks.

Constructor & Destructor Documentation

◆ thread_pool()

thread_pool::thread_pool ( std::size_t  _pool_size,
double  deviceAccuracy 
)
inlineexplicit

Thread pool constructor.

See also
thread_pool::pool_size
Parameters
deviceAccuracyParameter used to handle randomness generation impact on simulation results

Member Function Documentation

◆ getAvailableResourceSetIndex()

int thread_pool::getAvailableResourceSetIndex ( )
inlineprivate

Obtain the index of an available resource set.

Resource set is composed of: apMatrices[index] randGens[index] randGens2[index]

Returns
Available resource set index

◆ getPoolSize()

std::size_t thread_pool::getPoolSize ( )
inline

Obtain the thread pool size.

Returns
Thread pool size
See also
thread_pool::pool_size

◆ wrap_task()

void thread_pool::wrap_task ( )
inlineprivate

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

◆ apMatrices

std::vector<std::vector<double> >* thread_pool::apMatrices
private

Alpha prime matrices for MarquardtFitter. One per possible thread, to avoid spamming reallocations

◆ resourceSetAvailable

bool* thread_pool::resourceSetAvailable
private

Array of flags specifying availability of resource sets.

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

◆ work_

boost::asio::io_service::work thread_pool::work_
private

Instance of work to report the io service when it has pending tasks.

See also
thread_pool::io_service_

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