HIPO  4.3.0
High Performance Output data format for experimental physics
ThreadPool Class Reference

A ThreadPool implementation for managing asynchronous task execution. More...

#include <threadpool.hpp>

Classes

struct  Statistics
 Runtime statistics for thread pool performance monitoring. More...
 

Public Types

enum class  ShutdownResult { Graceful , Forced , AlreadyStopped }
 Result status of thread pool shutdown. More...
 

Public Member Functions

 ThreadPool (std::size_t num_threads=0, std::string_view thread_name_prefix="ThreadPool")
 Constructs a ThreadPool with specified number of worker threads. More...
 
 ~ThreadPool () noexcept
 Destructor ensures graceful shutdown with reasonable timeout. More...
 
 ThreadPool (const ThreadPool &)=delete
 
ThreadPooloperator= (const ThreadPool &)=delete
 
 ThreadPool (ThreadPool &&) noexcept
 
ThreadPooloperator= (ThreadPool &&) noexcept
 
template<typename Callable , typename... Args>
auto submit (Callable &&callable, Args &&... args) -> std::future< std::invoke_result_t< std::decay_t< Callable >, std::decay_t< Args >... >>
 Submits a task for asynchronous execution. More...
 
auto shutdown (std::chrono::milliseconds timeout=std::chrono::seconds{5}) noexcept -> void
 Initiates graceful shutdown with specified timeout. More...
 
auto wait_for_idle (std::chrono::milliseconds timeout=std::chrono::milliseconds::max()) const -> bool
 Waits for all pending tasks to complete. More...
 
auto thread_count () const noexcept -> std::size_t
 Gets the number of worker threads. More...
 
auto pending_tasks () const noexcept -> std::size_t
 Gets the number of pending tasks. More...
 
auto is_running () const noexcept -> bool
 Checks if the pool is running (not stopped). More...
 
auto get_statistics () const noexcept -> const Statistics &
 Gets current statistics snapshot. More...
 

Detailed Description

A ThreadPool implementation for managing asynchronous task execution.

Provides a thread pool that distributes work across multiple worker threads, with support for task submission via futures, graceful shutdown, and runtime statistics.

Definition at line 35 of file threadpool.hpp.

Member Enumeration Documentation

◆ ShutdownResult

Result status of thread pool shutdown.

Enumerator
Graceful 

All tasks completed within timeout.

Forced 

Timeout exceeded, threads detached.

AlreadyStopped 

Pool was already stopped.

Definition at line 40 of file threadpool.hpp.

Constructor & Destructor Documentation

◆ ThreadPool()

ThreadPool::ThreadPool ( const ThreadPool )
delete

Member Function Documentation

◆ get_statistics()

auto ThreadPool::get_statistics ( ) const -> const Statistics&
inlinenoexcept

Gets current statistics snapshot.

Definition at line 139 of file threadpool.hpp.

◆ is_running()

auto ThreadPool::is_running ( ) const -> bool
inlinenoexcept

Checks if the pool is running (not stopped).

Definition at line 134 of file threadpool.hpp.

◆ operator=()

ThreadPool& ThreadPool::operator= ( const ThreadPool )
delete

◆ pending_tasks()

auto ThreadPool::pending_tasks ( ) const -> std::size_t
inlinenoexcept

Gets the number of pending tasks.

Definition at line 129 of file threadpool.hpp.

◆ thread_count()

auto ThreadPool::thread_count ( ) const -> std::size_t
inlinenoexcept

Gets the number of worker threads.

Definition at line 124 of file threadpool.hpp.


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