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

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

#include <global_pool_backend.hpp>

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::detail::global_pool_backend< 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 54 of file global_pool_backend.hpp.

Member Function Documentation

◆ init()

template<typename PoolType >
static void threadschedule::detail::global_pool_backend< 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 64 of file global_pool_backend.hpp.

Referenced by threadschedule::advanced::global_thread_pool::init(), and threadschedule::advanced::global_work_stealing_pool::init().

◆ instance()

◆ parallel_for_each()

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

◆ post()

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

◆ submit()

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

◆ submit_batch()

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

◆ try_post()

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

◆ try_submit()

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

◆ try_submit_batch()

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

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