libstp
Robotics library for Botball
Loading...
Searching...
No Matches
libstp::threading::ThreadPool Class Reference

#include <thread_pool.hpp>

Public Member Functions

 ThreadPool (std::size_t worker_count=0)
 ~ThreadPool ()
 ThreadPool (const ThreadPool &)=delete
ThreadPool & operator= (const ThreadPool &)=delete
template<typename F, typename... Args>
auto submit (F &&fn, Args &&... args) -> std::future< std::invoke_result_t< std::decay_t< F >, std::decay_t< Args >... > >
void wait_idle ()
 Block until the queue is empty and no tasks are in flight.
void shutdown ()
 Stop accepting new tasks and join all workers. Idempotent.
std::size_t worker_count () const noexcept

Detailed Description

Fixed-size worker pool for short-lived tasks.

Workers are jthreads (jthread on platforms that ship it, a minimal compat fallback otherwise); the destructor requests stop, drains the queue, and joins. Submitted tasks return a std::future so callers can await results or exceptions.

Intended for fan-out compute (e.g. parallel motion-controller updates or sensor preprocessing). It is NOT a general-purpose async runtime — blocking I/O or unbounded waits will starve the pool.

Definition at line 29 of file thread_pool.hpp.

Constructor & Destructor Documentation

◆ ThreadPool() [1/2]

libstp::threading::ThreadPool::ThreadPool ( std::size_t worker_count = 0)
explicit

◆ ~ThreadPool()

libstp::threading::ThreadPool::~ThreadPool ( )

◆ ThreadPool() [2/2]

libstp::threading::ThreadPool::ThreadPool ( const ThreadPool & )
delete

Member Function Documentation

◆ operator=()

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

◆ shutdown()

void libstp::threading::ThreadPool::shutdown ( )

Stop accepting new tasks and join all workers. Idempotent.

◆ submit()

template<typename F, typename... Args>
auto libstp::threading::ThreadPool::submit ( F && fn,
Args &&... args )->std::future< std::invoke_result_t< std::decay_t< F >, std::decay_t< Args >... > >
inline

Submit a callable; returns a future for the result. Throws std::runtime_error if the pool has already been shut down.

Definition at line 41 of file thread_pool.hpp.

◆ wait_idle()

void libstp::threading::ThreadPool::wait_idle ( )

Block until the queue is empty and no tasks are in flight.

◆ worker_count()

std::size_t libstp::threading::ThreadPool::worker_count ( ) const
inlinenodiscardnoexcept

Definition at line 62 of file thread_pool.hpp.


The documentation for this class was generated from the following file:
  • /home/runner/work/raccoon-lib/raccoon-lib/modules/libstp-threading/include/threading/thread_pool.hpp