ThreadSchedule 1.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
threadschedule::GlobalThreadPool Class Reference

Singleton accessor for a process-wide ThreadPool instance. More...

#include <thread_pool.hpp>

Static Public Member Functions

static auto instance () -> ThreadPool &
template<typename F, typename... Args>
static auto submit (F &&f, Args &&... args)
template<typename Iterator>
static auto submit_range (Iterator begin, Iterator end)
template<typename Iterator, typename F>
static void parallel_for_each (Iterator begin, Iterator end, F &&func)

Detailed Description

Singleton accessor for a process-wide ThreadPool instance.

Provides static convenience methods that forward to a single ThreadPool whose lifetime is managed as a function-local static (Meyer's singleton).

Thread safety
The underlying ThreadPool is created on the first call to instance() and is guaranteed to be thread-safe in C++11 and later (magic statics). All forwarded methods (submit, submit_range, parallel_for_each) are as thread-safe as the corresponding ThreadPool methods.
Pool size
The pool is created with std::thread::hardware_concurrency() threads. This size is fixed for the lifetime of the process; there is no API to resize the singleton pool after creation.
Static destruction order
Because the pool is a function-local static, it is destroyed during static destruction in reverse order of construction. Submitting work to the global pool from destructors of other static objects is undefined behaviour if the pool has already been destroyed. Prefer explicit lifetime management in programs with complex static initialization dependencies.
Copyability / movability
Not instantiable (private constructor). All access is through static methods.

Definition at line 1396 of file thread_pool.hpp.

Member Function Documentation

◆ instance()

auto threadschedule::GlobalThreadPool::instance ( ) -> ThreadPool&
inlinestatic

Definition at line 1399 of file thread_pool.hpp.

◆ parallel_for_each()

template<typename Iterator, typename F>
void threadschedule::GlobalThreadPool::parallel_for_each ( Iterator begin,
Iterator end,
F && func )
inlinestatic

Definition at line 1418 of file thread_pool.hpp.

◆ submit()

template<typename F, typename... Args>
auto threadschedule::GlobalThreadPool::submit ( F && f,
Args &&... args )
inlinestatic

Definition at line 1406 of file thread_pool.hpp.

◆ submit_range()

template<typename Iterator>
auto threadschedule::GlobalThreadPool::submit_range ( Iterator begin,
Iterator end )
inlinestatic

Definition at line 1412 of file thread_pool.hpp.


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