HIPO  4.3.0
High Performance Output data format for experimental physics
Concurrency

Thread pool and progress tracking utilities. More...

Classes

class  ProgressTracker
 Thread-safe progress tracker with visual progress bar. More...
 
class  ThreadPool
 A ThreadPool implementation for managing asynchronous task execution. More...
 

Functions

template<typename Callable , typename... Args>
auto ThreadPool::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 ThreadPool::Statistics::get_throughput () const noexcept -> double
 Calculates tasks completed per second. More...
 
auto ThreadPool::Statistics::get_uptime () const noexcept -> std::chrono::duration< double >
 Calculates time elapsed since pool creation. More...
 
 ThreadPool::Statistics::Statistics (Statistics &&other) noexcept
 Move constructor; transfers statistics state. More...
 
StatisticsThreadPool::Statistics::operator= (Statistics &&other) noexcept
 Move assignment; transfers statistics state. More...
 
 ThreadPool::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::~ThreadPool () noexcept
 Destructor ensures graceful shutdown with reasonable timeout. More...
 
 ThreadPool::ThreadPool (ThreadPool &&) noexcept
 
ThreadPoolThreadPool::operator= (ThreadPool &&) noexcept
 
auto ThreadPool::shutdown (std::chrono::milliseconds timeout=std::chrono::seconds{5}) noexcept -> void
 Initiates graceful shutdown with specified timeout. More...
 
auto ThreadPool::wait_for_idle (std::chrono::milliseconds timeout=std::chrono::milliseconds::max()) const -> bool
 Waits for all pending tasks to complete. More...
 

Detailed Description

Thread pool and progress tracking utilities.

Function Documentation

◆ get_throughput()

auto ThreadPool::Statistics::get_throughput ( ) const -> double
inlinenoexcept

Calculates tasks completed per second.

Returns
throughput as tasks per second

Definition at line 191 of file threadpool.hpp.

◆ get_uptime()

auto ThreadPool::Statistics::get_uptime ( ) const -> std::chrono::duration<double>
inlinenoexcept

Calculates time elapsed since pool creation.

Returns
uptime as a chrono duration

Definition at line 197 of file threadpool.hpp.

◆ operator=() [1/2]

ThreadPool::Statistics & ThreadPool::Statistics::operator= ( Statistics &&  other)
inlinenoexcept

Move assignment; transfers statistics state.

Definition at line 215 of file threadpool.hpp.

◆ operator=() [2/2]

ThreadPool & ThreadPool::operator= ( ThreadPool &&  other)
inlinenoexcept

Definition at line 272 of file threadpool.hpp.

◆ shutdown()

auto ThreadPool::shutdown ( std::chrono::milliseconds  timeout = std::chrono::seconds{5}) -> void
inlinenoexcept

Initiates graceful shutdown with specified timeout.

Parameters
timeoutMaximum time to wait for completion

Definition at line 292 of file threadpool.hpp.

◆ Statistics()

ThreadPool::Statistics::Statistics ( Statistics &&  other)
inlinenoexcept

Move constructor; transfers statistics state.

Definition at line 201 of file threadpool.hpp.

◆ submit()

template<typename Callable , typename... Args>
auto ThreadPool::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.

Parameters
callableFunction/callable object to execute
argsArguments to pass to the callable
Returns
Future for the result
Exceptions
std::runtime_errorif pool is stopped

Definition at line 162 of file threadpool.hpp.

◆ ThreadPool() [1/2]

ThreadPool::ThreadPool ( std::size_t  num_threads = 0,
std::string_view  thread_name_prefix = "ThreadPool" 
)
inlineexplicit

Constructs a ThreadPool with specified number of worker threads.

Parameters
num_threadsNumber of threads (0 = hardware_concurrency)
thread_name_prefixPrefix for thread names
Exceptions
std::system_errorif thread creation fails
std::invalid_argumentif num_threads > hardware limit

Definition at line 232 of file threadpool.hpp.

◆ ThreadPool() [2/2]

ThreadPool::ThreadPool ( ThreadPool &&  other)
inlinenoexcept

Definition at line 259 of file threadpool.hpp.

◆ wait_for_idle()

auto ThreadPool::wait_for_idle ( std::chrono::milliseconds  timeout = std::chrono::milliseconds::max()) const -> bool
inline

Waits for all pending tasks to complete.

Parameters
timeoutMaximum time to wait
Returns
true if all tasks completed within timeout

Definition at line 341 of file threadpool.hpp.

◆ ~ThreadPool()

ThreadPool::~ThreadPool ( )
inlinenoexcept

Destructor ensures graceful shutdown with reasonable timeout.

Definition at line 255 of file threadpool.hpp.