Libosmium: osmium::thread::Pool Class Reference

Libosmium Fast and flexible C++ library for working with OpenStreetMap data

Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
osmium::thread::Pool Class Reference

`#include <pool.hpp>`

Collaboration diagram for osmium::thread::Pool:
[legend]

## Classes
class | thread_joiner

## Public Types
enum | { default_num_threads = 0 }
enum | { default_queue_size = 0U }
template<typename TFunction>
using | submit_func_result_type = std::result_of_t<TFunction()>

## Public Member Functions
| Pool (int num_threads=default_num_threads, std::size_t max_queue_size=default_queue_size)
void | shutdown_all_workers ()
| Pool (const Pool &)=delete
Pool & | operator= (const Pool &)=delete
| Pool (Pool &&)=delete
Pool & | operator= (Pool &&)=delete
| ~Pool ()
int | num_threads () const noexcept
std::size_t | queue_size () const
bool | queue_empty () const
template<typename TFunction>
std::future< submit_func_result_type< TFunction > > | submit (TFunction &&func)

## Static Public Member Functions
static Pool & | default_instance ()

## Private Member Functions
void | worker_thread ()

## Private Attributes
osmium::thread::Queue< function_wrapper > | m_work_queue
std::vector< std::thread > | m_threads
thread_joiner | m_joiner
int | m_num_threads

## Detailed Description

Thread pool.

## Member Typedef Documentation

## ◆ submit_func_result_type

template<typename TFunction>

using osmium::thread::Pool::submit_func_result_type = std::result_of_t<TFunction()>

## Member Enumeration Documentation

## ◆ anonymous enum

anonymous enum

Enumerator
default_num_threads |

## ◆ anonymous enum

anonymous enum

Enumerator
default_queue_size |

## Constructor & Destructor Documentation

## ◆ Pool() [1/3]

osmium::thread::Pool::Pool | ( | int | num_threads = default_num_threads,
|  | std::size_t | max_queue_size = default_queue_size )
| inlineexplicit

Create thread pool with the given number of threads. If num_threads is 0, the number of threads is read from the environment variable OSMIUM_POOL_THREADS. The default value in that case is -2.

If the number of threads is a negative number, it will be set to the actual number of cores on the system plus the given number, ie it will leave a number of cores unused.

In all cases the minimum number of threads in the pool is 1.

If max_queue_size is 0, the queue size is read from the environment variable OSMIUM_MAX_WORK_QUEUE_SIZE.

## ◆ Pool() [2/3]

osmium::thread::Pool::Pool | ( | const Pool & |  | ) |
| delete

## ◆ Pool() [3/3]

osmium::thread::Pool::Pool | ( | Pool && |  | ) |
| delete

## ◆ ~Pool()

osmium::thread::Pool::~Pool | ( |  | ) |
| inline

## Member Function Documentation

## ◆ default_instance()

Pool & osmium::thread::Pool::default_instance | ( |  | ) |
| inlinestatic

Return a statically created "default pool". This is initialized the first time you use it.

Do not use this if your program will fork.

## ◆ num_threads()

int osmium::thread::Pool::num_threads | ( |  | ) | const
| inlinenoexcept

## ◆ operator=() [1/2]

Pool & osmium::thread::Pool::operator= | ( | const Pool & |  | ) |
| delete

## ◆ operator=() [2/2]

Pool & osmium::thread::Pool::operator= | ( | Pool && |  | ) |
| delete

## ◆ queue_empty()

bool osmium::thread::Pool::queue_empty | ( |  | ) | const
| inline

## ◆ queue_size()

std::size_t osmium::thread::Pool::queue_size | ( |  | ) | const
| inline

## ◆ shutdown_all_workers()

void osmium::thread::Pool::shutdown_all_workers | ( |  | ) |
| inline

## ◆ submit()

template<typename TFunction>

std::future< submit_func_result_type< TFunction > > osmium::thread::Pool::submit | ( | TFunction && | func | ) |
| inline

## ◆ worker_thread()

void osmium::thread::Pool::worker_thread | ( |  | ) |
| inlineprivate

## Member Data Documentation

## ◆ m_joiner

thread_joiner osmium::thread::Pool::m_joiner
| private

## ◆ m_num_threads

int osmium::thread::Pool::m_num_threads
| private

## ◆ m_threads

std::vector<std::thread> osmium::thread::Pool::m_threads
| private

## ◆ m_work_queue

osmium::thread::Queue<function_wrapper> osmium::thread::Pool::m_work_queue
| private

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

- include/osmium/thread/pool.hpp