Gazebo Common

API Reference

5.7.0
WorkerPool Class Reference

A pool of worker threads that do stuff in parallel. More...

#include <WorkerPool.hh>

Public Member Functions

 WorkerPool (const unsigned int _minThreadCount=1u)
 Creates worker threads. The number of worker threads is determined by max(std::thread::hardware_concurrency, _minThreadCount). More...
 
 ~WorkerPool ()
 closes worker threads More...
 
void AddWork (std::function< void()> _work, std::function< void()> _cb=std::function< void()>())
 Adds work to the worker pool with optional callback. More...
 
bool WaitForResults (const std::chrono::steady_clock::duration &_timeout=std::chrono::steady_clock::duration::zero())
 Waits until all work is done and threads are idle. More...
 

Detailed Description

A pool of worker threads that do stuff in parallel.

Constructor & Destructor Documentation

◆ WorkerPool()

WorkerPool ( const unsigned int  _minThreadCount = 1u)
explicit

Creates worker threads. The number of worker threads is determined by max(std::thread::hardware_concurrency, _minThreadCount).

Parameters
[in]_minThreadCountThe minimum number of threads to create in the pool. A value of zero is converted to a value of 1.
Note
It's not recommended to set _minThreadCount greater than std::thread::hardware_concurrency.

◆ ~WorkerPool()

~WorkerPool ( )

closes worker threads

Member Function Documentation

◆ AddWork()

void AddWork ( std::function< void()>  _work,
std::function< void()>  _cb = std::function< void()>() 
)

Adds work to the worker pool with optional callback.

Parameters
[in]_workfunction to do one piece of work
[in]_cboptional callback when the work is done
Remarks
Typical work is a function bound with arguments. It must

◆ WaitForResults()

bool WaitForResults ( const std::chrono::steady_clock::duration &  _timeout = std::chrono::steady_clock::duration::zero())

Waits until all work is done and threads are idle.

Parameters
[in]_timeoutHow long to wait, default to forever
Returns
true if all work was finished
Remarks
The return value can be false even when waiting forever if

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