ThreadPool Class Reference

Detailed Description

Creates a pool of threads and a pool of tasks to be executed by the threads simultaneously.

Expected use of this class follows:

The API is not guaranteed to be thread safe. This class is provided to speed up build and load processes among others which are necessary but not part of the API. Use it with caution.

#include <include/maliput/utility/thread_pool.h>

Public Member Functions

 ThreadPool (std::size_t n)
 Creates a pool of n threads. More...
 ~ThreadPool ()
template<class F , class R = std::result_of_t<F&()>>
std::future< R > Queue (F &&f)
 Adds tasks to the queue. More...
void Start ()
 Starts the threads to work on the tasks. More...
void Finish ()
 Finishes the threads. More...
void cancel_pending ()
 Cancels all non-started tasks. More...
bool is_running ()

Constructor & Destructor Documentation

◆ ThreadPool()

ThreadPool ( std::size_t  n)

Creates a pool of n threads.

nIs the number of threads to be managed.
WhenN is equal to zero.

◆ ~ThreadPool()

~ThreadPool ( )

Member Function Documentation

◆ cancel_pending()

void cancel_pending ( )

Cancels all non-started tasks.

◆ Finish()

void Finish ( )

Finishes the threads.

Waits for all tasks previously added to finish before destroying the threads.

◆ is_running()

bool is_running ( )
True when the threads are already started.



◆ Queue()

std::future<R> Queue ( F &&  f)

Adds tasks to the queue.

Template Parameters
FIs the functor type.
fIs the task.
Template Parameters
RIs the functors return type. @return A std::future<R> that will hold the result off`.
maliput::common::assertion_errorWhen Finish() method was already called.

◆ Start()

void Start ( )

Starts the threads to work on the tasks.

The main thread will not perform any task and will continue the execution.

maliput::common::assertion_errorWhen this method is called consecutively without finishing the threads.

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