ThreadSchedule 2.0.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 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
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, non-movable. 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 32 of file thread_pool_with_errors.hpp.

Constructor & Destructor Documentation

◆ PoolWithErrors()

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

Definition at line 35 of file thread_pool_with_errors.hpp.

Member Function Documentation

◆ add_error_callback()

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

Definition at line 69 of file thread_pool_with_errors.hpp.

◆ clear_error_callbacks()

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

Definition at line 79 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 104 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 115 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 84 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 99 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 135 of file thread_pool_with_errors.hpp.

◆ pool()

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

Definition at line 94 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 74 of file thread_pool_with_errors.hpp.

◆ reset_error_count()

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

Definition at line 89 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 110 of file thread_pool_with_errors.hpp.

◆ shutdown()

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

Definition at line 125 of file thread_pool_with_errors.hpp.

◆ size()

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

Definition at line 130 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 44 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 53 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 63 of file thread_pool_with_errors.hpp.

◆ wait_for_tasks()

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

Definition at line 120 of file thread_pool_with_errors.hpp.


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