Helios++
Helios software for LiDAR simulations
|
Thread pool which starts thread so they are always waiting for new tasks to be posted to the warehouse to compute them. More...
#include <WarehouseThreadPool.h>
Public Member Functions | |
virtual bool | post (shared_ptr< Task > task) |
Expose the warehouse post method. More... | |
virtual bool | post (vector< shared_ptr< Task >> &tasks) |
Expose the warehouse post method. More... | |
virtual shared_ptr< Task > | get () |
Expose the warehouse get method. More... | |
virtual void | notify () |
Expose the warehouse notify method. More... | |
virtual void | notifyAll () |
Expose the warehouse notify all method. More... | |
virtual void | start () |
Start the warehouse thread pool. More... | |
virtual void | join () |
Lock until warehouse is empty. | |
virtual void | finish () |
Finish the warehouse thread pool in a proper way. It is, allowing all tasks to finish properly and emptying the warehouse. More... | |
![]() | |
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 | |
WarehouseThreadPool (std::size_t const _pool_size, std::size_t const maxTasks=256) | |
Warehouse thread pool constructor. More... | |
virtual void | _start (size_t const tid) |
Start a thread. More... | |
virtual void | doTask (size_t const tid, shared_ptr< Task > task) |
Thread execute given task. By default it assumes task must be called with no arguments. To handle tasks with arguments extend the WarehouseThreadPool and override this method accordingly. More... | |
virtual void | finalJoin () |
Lock until all pending tasks have been finished. If it is not called after finish, it will lead to an eternal waiting. More... | |
Protected Attributes | |
TaskWarehouse< Task > | warehouse |
The task warehouse used to handle tasks. | |
bool | working |
True if thread pool is working, false if it is already finished. More... | |
int | workersCount |
Count how many active workers there are. It is used for final join. | |
int | pendingCount |
Count how many workers with pending tasks there are. It is used for join (not final join). It can also be read as working count (not workers count) because it counts how many working threads there are. | |
boost::mutex | mtx |
Mutex to handle concurrent access to workers count. | |
boost::condition_variable | condvar |
Conditional variable to handle concurrent access to workers count. | |
boost::mutex | joinMtx |
Mutex to handle join until warehouse is empty (not the final join) More... | |
boost::condition_variable | joinCondvar |
Conditional variable to handle join until warehouse is empty (not the final join) More... | |
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) | |
![]() | |
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. | |
Thread pool which starts thread so they are always waiting for new tasks to be posted to the warehouse to compute them.
Task | The type of task handled by the warehouse thread pool |
|
inlineexplicitprotected |
Warehouse thread pool constructor.
|
inlineprotectedvirtual |
Start a thread.
Started threads compute tasks from warehouse. If there are not remaining tasks they wait for a notify signal to resume its activity, to avoid active listening. To stop threads the WarehouseThreadPool::finish method must be invoked.
tid | Index for thread to be started |
|
inlineprotectedvirtual |
Thread execute given task. By default it assumes task must be called with no arguments. To handle tasks with arguments extend the WarehouseThreadPool and override this method accordingly.
tid | Index/identifier of thread that must compute the task |
task | Task to be computed |
Reimplemented in PulseWarehouseThreadPool.
|
inlineprotectedvirtual |
Lock until all pending tasks have been finished. If it is not called after finish, it will lead to an eternal waiting.
|
inlinevirtual |
Finish the warehouse thread pool in a proper way. It is, allowing all tasks to finish properly and emptying the warehouse.
|
inlinevirtual |
Expose the warehouse get method.
|
inlinevirtual |
Expose the warehouse notify method.
|
inlinevirtual |
Expose the warehouse notify all method.
|
inlinevirtual |
Expose the warehouse post method.
|
inlinevirtual |
Expose the warehouse post method.
|
inlinevirtual |
Start the warehouse thread pool.
A non started warehouse thread pool will not compute any posted task until it is started.
|
protected |
Conditional variable to handle join until warehouse is empty (not the final join)
|
protected |
Mutex to handle join until warehouse is empty (not the final join)
|
protected |
True if thread pool is working, false if it is already finished.
NOTICE that if working is true threads are guaranteed to be started and not finished. In consequence, threads might be computing tasks or waiting for new tasks. A warehouse thread pool with all threads waiting for tasks is considered as working. A warehouse thread pool is not working only if it has finished accepting tasks.