ThreadSchedule 2.2.0
Modern C++ thread management library
Loading...
Searching...
No Matches
threadschedule::GlobalPool< PoolType > Class Template Reference

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

#include <thread_pool.hpp>

Inheritance diagram for threadschedule::GlobalPool< PoolType >:
[legend]

Static Public Member Functions

static void init (size_t num_threads)
 Pre-configure the number of threads before first use.
static auto instance () -> PoolType &
 Access the singleton pool instance (created on first call).
Forwarding wrappers

All methods below simply forward to instance().method(...).

template<typename F, typename... Args>
static auto submit (F &&f, Args &&... args)
template<typename F, typename... Args>
static auto try_submit (F &&f, Args &&... args)
template<typename F, typename... Args>
static void post (F &&f, Args &&... args)
template<typename F, typename... Args>
static auto try_post (F &&f, Args &&... args)
template<typename Iterator>
static auto submit_batch (Iterator begin, Iterator end)
template<typename Iterator>
static auto try_submit_batch (Iterator begin, Iterator end)
template<typename Iterator, typename F>
static void parallel_for_each (Iterator begin, Iterator end, F &&func)

Detailed Description

template<typename PoolType>
class threadschedule::GlobalPool< PoolType >

Singleton accessor for a process-wide pool instance.

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

Thread safety
The underlying pool 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 are as thread-safe as the corresponding pool methods.
Pool size
The pool is created with std::thread::hardware_concurrency() threads. This size is fixed for the lifetime of the process.
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.
Copyability / movability
Not instantiable (private constructor). All access is through static methods.
Template Parameters
PoolTypeThe concrete pool type to wrap.

Definition at line 2266 of file thread_pool.hpp.

Member Function Documentation

◆ init()

template<typename PoolType>
void threadschedule::GlobalPool< PoolType >::init ( size_t num_threads)
inlinestatic

Pre-configure the number of threads before first use.

Must be called before instance() is first invoked. Subsequent calls are ignored (std::call_once semantics).

Definition at line 2275 of file thread_pool.hpp.

◆ instance()

template<typename PoolType>
auto threadschedule::GlobalPool< PoolType >::instance ( ) -> PoolType&
inlinestatic

Access the singleton pool instance (created on first call).

Definition at line 2281 of file thread_pool.hpp.

◆ parallel_for_each()

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

Definition at line 2328 of file thread_pool.hpp.

◆ post()

template<typename PoolType>
template<typename F, typename... Args>
void threadschedule::GlobalPool< PoolType >::post ( F && f,
Args &&... args )
inlinestatic

Definition at line 2304 of file thread_pool.hpp.

◆ submit()

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

Definition at line 2292 of file thread_pool.hpp.

◆ submit_batch()

template<typename PoolType>
template<typename Iterator>
auto threadschedule::GlobalPool< PoolType >::submit_batch ( Iterator begin,
Iterator end )
inlinestatic

Definition at line 2316 of file thread_pool.hpp.

◆ try_post()

template<typename PoolType>
template<typename F, typename... Args>
auto threadschedule::GlobalPool< PoolType >::try_post ( F && f,
Args &&... args )
inlinestatic

Definition at line 2310 of file thread_pool.hpp.

◆ try_submit()

template<typename PoolType>
template<typename F, typename... Args>
auto threadschedule::GlobalPool< PoolType >::try_submit ( F && f,
Args &&... args )
inlinestatic

Definition at line 2298 of file thread_pool.hpp.

◆ try_submit_batch()

template<typename PoolType>
template<typename Iterator>
auto threadschedule::GlobalPool< PoolType >::try_submit_batch ( Iterator begin,
Iterator end )
inlinestatic

Definition at line 2322 of file thread_pool.hpp.


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