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

Thread pool wrapper that combines any pool type with an ErrorHandler. More...

#include <thread_pool_with_errors.hpp>

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

Public Member Functions

 PoolWithErrors (size_t num_threads=std::thread::hardware_concurrency())
template<typename Arg1, typename Arg2, typename... Args>
 PoolWithErrors (Arg1 &&arg1, Arg2 &&arg2, Args &&... args)
 Construct with forwarded pool arguments.
template<typename F, typename... Args>
auto submit (F &&f, Args &&... args) -> FutureWithErrorHandler< std::invoke_result_t< F, Args... > >
 Submit a task with automatic error handling.
template<typename F, typename... Args>
auto submit_with_description (std::string const &description, F &&f, Args &&... args) -> FutureWithErrorHandler< std::invoke_result_t< F, Args... > >
 Submit a task with a description for better error messages.
template<typename F, typename... Args>
auto try_submit (F &&f, Args &&... args) -> expected< FutureWithErrorHandler< std::invoke_result_t< F, Args... > >, std::error_code >
 Submit a task, returning an error instead of throwing on shutdown.
auto add_error_callback (ErrorCallback callback) -> size_t
template<typename Callback, std::enable_if_t<!std::is_same_v< detail::remove_cvref_t< Callback >, ErrorCallback >, int > = 0>
auto add_error_callback (Callback &&callback) -> size_t
auto remove_error_callback (size_t id) -> bool
void clear_error_callbacks ()
auto error_count () const -> size_t
void reset_error_count ()
auto pool () -> PoolType &
auto get_statistics () const -> decltype(auto)
auto configure_threads (std::string const &name_prefix, SchedulingPolicy policy=SchedulingPolicy::OTHER, ThreadPriority priority=ThreadPriority::normal()) -> decltype(auto)
auto set_affinity (ThreadAffinity const &affinity) -> decltype(auto)
auto distribute_across_cpus () -> decltype(auto)
void wait_for_tasks ()
void shutdown ()
auto size () const noexcept -> size_t
auto pending_tasks () const -> size_t

Detailed Description

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

Thread pool wrapper that combines any pool type with an ErrorHandler.

Non-copyable; implicitly movable (default move operations). Thread-safe (delegates to the underlying pool).

submit() wraps every task so that exceptions are both reported to the ErrorHandler (via registered callbacks) and re-thrown, making them accessible through the returned FutureWithErrorHandler. submit_with_description() additionally attaches a user-supplied description string to the error report for easier diagnostics.

See also
FutureWithErrorHandler, ErrorHandler, TaskError
Template Parameters
PoolTypeThe underlying pool type (e.g. ThreadPool, FastThreadPool, HighPerformancePool).

Definition at line 33 of file thread_pool_with_errors.hpp.

Constructor & Destructor Documentation

◆ PoolWithErrors() [1/2]

template<typename PoolType>
threadschedule::PoolWithErrors< PoolType >::PoolWithErrors ( size_t num_threads = std::thread::hardware_concurrency())
inlineexplicit

Definition at line 36 of file thread_pool_with_errors.hpp.

◆ PoolWithErrors() [2/2]

template<typename PoolType>
template<typename Arg1, typename Arg2, typename... Args>
threadschedule::PoolWithErrors< PoolType >::PoolWithErrors ( Arg1 && arg1,
Arg2 && arg2,
Args &&... args )
inlineexplicit

Construct with forwarded pool arguments.

Enables passing pool-specific constructor arguments (e.g. deque_capacity for HighPerformancePool) while still attaching the error handler.

PoolWithErrors(size_t num_threads=std::thread::hardware_concurrency())

Definition at line 53 of file thread_pool_with_errors.hpp.

Member Function Documentation

◆ add_error_callback() [1/2]

template<typename PoolType>
template<typename Callback, std::enable_if_t<!std::is_same_v< detail::remove_cvref_t< Callback >, ErrorCallback >, int > = 0>
auto threadschedule::PoolWithErrors< PoolType >::add_error_callback ( Callback && callback) -> size_t
inline

Definition at line 95 of file thread_pool_with_errors.hpp.

◆ add_error_callback() [2/2]

template<typename PoolType>
auto threadschedule::PoolWithErrors< PoolType >::add_error_callback ( ErrorCallback callback) -> size_t
inline

Definition at line 88 of file thread_pool_with_errors.hpp.

◆ clear_error_callbacks()

template<typename PoolType>
void threadschedule::PoolWithErrors< PoolType >::clear_error_callbacks ( )
inline

Definition at line 105 of file thread_pool_with_errors.hpp.

◆ configure_threads()

template<typename PoolType>
auto threadschedule::PoolWithErrors< PoolType >::configure_threads ( std::string const & name_prefix,
SchedulingPolicy policy = SchedulingPolicy::OTHER,
ThreadPriority priority = ThreadPriority::normal() ) -> decltype(auto)
inline

Definition at line 130 of file thread_pool_with_errors.hpp.

◆ distribute_across_cpus()

template<typename PoolType>
auto threadschedule::PoolWithErrors< PoolType >::distribute_across_cpus ( ) -> decltype(auto)
inline

Definition at line 141 of file thread_pool_with_errors.hpp.

◆ error_count()

template<typename PoolType>
auto threadschedule::PoolWithErrors< PoolType >::error_count ( ) const -> size_t
inlinenodiscard

Definition at line 110 of file thread_pool_with_errors.hpp.

◆ get_statistics()

template<typename PoolType>
auto threadschedule::PoolWithErrors< PoolType >::get_statistics ( ) const -> decltype(auto)
inlinenodiscard

Definition at line 125 of file thread_pool_with_errors.hpp.

◆ pending_tasks()

template<typename PoolType>
auto threadschedule::PoolWithErrors< PoolType >::pending_tasks ( ) const -> size_t
inlinenodiscard

Definition at line 161 of file thread_pool_with_errors.hpp.

◆ pool()

template<typename PoolType>
auto threadschedule::PoolWithErrors< PoolType >::pool ( ) -> PoolType&
inlinenodiscard

Definition at line 120 of file thread_pool_with_errors.hpp.

◆ remove_error_callback()

template<typename PoolType>
auto threadschedule::PoolWithErrors< PoolType >::remove_error_callback ( size_t id) -> bool
inline

Definition at line 100 of file thread_pool_with_errors.hpp.

◆ reset_error_count()

template<typename PoolType>
void threadschedule::PoolWithErrors< PoolType >::reset_error_count ( )
inline

Definition at line 115 of file thread_pool_with_errors.hpp.

◆ set_affinity()

template<typename PoolType>
auto threadschedule::PoolWithErrors< PoolType >::set_affinity ( ThreadAffinity const & affinity) -> decltype(auto)
inline

Definition at line 136 of file thread_pool_with_errors.hpp.

◆ shutdown()

template<typename PoolType>
void threadschedule::PoolWithErrors< PoolType >::shutdown ( )
inline

Definition at line 151 of file thread_pool_with_errors.hpp.

◆ size()

template<typename PoolType>
auto threadschedule::PoolWithErrors< PoolType >::size ( ) const -> size_t
inlinenodiscardnoexcept

Definition at line 156 of file thread_pool_with_errors.hpp.

◆ submit()

template<typename PoolType>
template<typename F, typename... Args>
auto threadschedule::PoolWithErrors< PoolType >::submit ( F && f,
Args &&... args ) -> FutureWithErrorHandler<std::invoke_result_t<F, Args...>>
inline

Submit a task with automatic error handling.

Definition at line 63 of file thread_pool_with_errors.hpp.

◆ submit_with_description()

template<typename PoolType>
template<typename F, typename... Args>
auto threadschedule::PoolWithErrors< PoolType >::submit_with_description ( std::string const & description,
F && f,
Args &&... args ) -> FutureWithErrorHandler<std::invoke_result_t<F, Args...>>
inline

Submit a task with a description for better error messages.

Definition at line 72 of file thread_pool_with_errors.hpp.

◆ try_submit()

template<typename PoolType>
template<typename F, typename... Args>
auto threadschedule::PoolWithErrors< PoolType >::try_submit ( F && f,
Args &&... args ) -> expected<FutureWithErrorHandler<std::invoke_result_t<F, Args...>>, std::error_code>
inline

Submit a task, returning an error instead of throwing on shutdown.

Definition at line 82 of file thread_pool_with_errors.hpp.

◆ wait_for_tasks()

template<typename PoolType>
void threadschedule::PoolWithErrors< PoolType >::wait_for_tasks ( )
inline

Definition at line 146 of file thread_pool_with_errors.hpp.


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