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

High-performance thread pool optimized for high-frequency task submission. More...

#include <thread_pool.hpp>

Classes

struct  Statistics

Public Types

using Task = std::function<void()>

Public Member Functions

 HighPerformancePool (size_t num_threads=std::thread::hardware_concurrency())
 HighPerformancePool (HighPerformancePool const &)=delete
auto operator= (HighPerformancePool const &) -> HighPerformancePool &=delete
template<typename F, typename... Args>
auto submit (F &&f, Args &&... args) -> std::future< std::invoke_result_t< F, Args... > >
 High-performance task submission (optimized hot path)
template<typename Iterator>
auto submit_batch (Iterator begin, Iterator end) -> std::vector< std::future< void > >
 Batch task submission for maximum throughput.
template<typename Iterator, typename F>
void parallel_for_each (Iterator begin, Iterator end, F &&func)
 Optimized parallel for_each with work distribution.
auto size () const noexcept -> size_t
auto pending_tasks () const -> size_t
auto configure_threads (std::string const &name_prefix, SchedulingPolicy policy=SchedulingPolicy::OTHER, ThreadPriority priority=ThreadPriority::normal()) -> expected< void, std::error_code >
 Configure all worker threads.
auto set_affinity (ThreadAffinity const &affinity) -> expected< void, std::error_code >
auto distribute_across_cpus () -> expected< void, std::error_code >
void wait_for_tasks ()
void shutdown ()
auto get_statistics () const -> Statistics
 Get detailed performance statistics.

Detailed Description

High-performance thread pool optimized for high-frequency task submission.

Optimizations for 1k+ tasks with 10k+ tasks/second throughput:

  • Work-stealing architecture with proper synchronization
  • Per-thread queues with efficient load balancing
  • Batch processing support for maximum throughput
  • Optimized wake-up mechanisms
  • Cache-friendly data structures with proper alignment
  • Performance monitoring and statistics

Note: Has overhead for small task counts (< 100 tasks) due to work-stealing complexity. Best for high-throughput scenarios like image processing, batch operations, etc.

Definition at line 149 of file thread_pool.hpp.

Member Typedef Documentation

◆ Task

using threadschedule::HighPerformancePool::Task = std::function<void()>

Definition at line 152 of file thread_pool.hpp.

Constructor & Destructor Documentation

◆ HighPerformancePool()

threadschedule::HighPerformancePool::HighPerformancePool ( size_t num_threads = std::thread::hardware_concurrency())
inlineexplicit

Definition at line 165 of file thread_pool.hpp.

◆ ~HighPerformancePool()

threadschedule::HighPerformancePool::~HighPerformancePool ( )
inline

Definition at line 188 of file thread_pool.hpp.

Member Function Documentation

◆ configure_threads()

auto threadschedule::HighPerformancePool::configure_threads ( std::string const & name_prefix,
SchedulingPolicy policy = SchedulingPolicy::OTHER,
ThreadPriority priority = ThreadPriority::normal() ) -> expected<void, std::error_code>
inline

Configure all worker threads.

Definition at line 350 of file thread_pool.hpp.

◆ distribute_across_cpus()

auto threadschedule::HighPerformancePool::distribute_across_cpus ( ) -> expected<void, std::error_code>
inline

Definition at line 390 of file thread_pool.hpp.

◆ get_statistics()

auto threadschedule::HighPerformancePool::get_statistics ( ) const -> Statistics
inline

Get detailed performance statistics.

Definition at line 444 of file thread_pool.hpp.

Referenced by threadschedule::HighPerformancePoolWithErrors::get_statistics().

◆ parallel_for_each()

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

Optimized parallel for_each with work distribution.

Definition at line 298 of file thread_pool.hpp.

References submit().

◆ pending_tasks()

auto threadschedule::HighPerformancePool::pending_tasks ( ) const -> size_t
inline

Definition at line 334 of file thread_pool.hpp.

◆ set_affinity()

auto threadschedule::HighPerformancePool::set_affinity ( ThreadAffinity const & affinity) -> expected<void, std::error_code>
inline

Definition at line 374 of file thread_pool.hpp.

◆ shutdown()

void threadschedule::HighPerformancePool::shutdown ( )
inline

Definition at line 418 of file thread_pool.hpp.

◆ size()

auto threadschedule::HighPerformancePool::size ( ) const -> size_t
inlinenoexcept

Definition at line 329 of file thread_pool.hpp.

◆ submit()

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

High-performance task submission (optimized hot path)

Definition at line 197 of file thread_pool.hpp.

Referenced by parallel_for_each().

◆ submit_batch()

template<typename Iterator>
auto threadschedule::HighPerformancePool::submit_batch ( Iterator begin,
Iterator end ) -> std::vector<std::future<void>>
inline

Batch task submission for maximum throughput.

Definition at line 250 of file thread_pool.hpp.

◆ wait_for_tasks()

void threadschedule::HighPerformancePool::wait_for_tasks ( )
inline

Definition at line 411 of file thread_pool.hpp.


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