|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
A modern, efficient thread pool for parallel task execution. More...
#include <future>#include <queue>#include <functional>#include <algorithm>#include <condition_variable>#include <atomic>#include <vector>#include <list>#include <thread>#include <mutex>#include <stdexcept>#include <type_traits>#include <tuple>#include <memory>#include <limits>#include <optional>#include <chrono>#include <numeric>#include <iterator>#include <string>Go to the source code of this file.
Classes | |
| class | Aleph::operation_canceled |
| Exception thrown when cooperative cancellation is observed. More... | |
| struct | Aleph::CancellationState |
| Shared state for cooperative cancellation. More... | |
| struct | Aleph::cancellation_detail::Locked_Observer |
| A condition variable registered with the mutex of its waiters. More... | |
| struct | Aleph::cancellation_detail::Exact_State |
| State created by a CancellationSource. More... | |
| class | Aleph::CancellationToken |
| Read-only cooperative cancellation token. More... | |
| class | Aleph::CancellationToken::ConditionVariableRegistration |
| RAII guard for condition variable cancellation registration. More... | |
| class | Aleph::CancellationSource |
| Cooperative cancellation source paired with CancellationToken. More... | |
| struct | Aleph::ParallelOptions |
| Common configuration object for parallel algorithms. More... | |
| class | Aleph::queue_overflow_error |
| Exception thrown when the task queue exceeds its hard limit. More... | |
| struct | Aleph::ThreadPoolStats |
| Statistics collected by ThreadPool. More... | |
| class | Aleph::ThreadPool |
| A reusable thread pool for efficient parallel task execution. More... | |
| struct | Aleph::ThreadPool::TaskBase |
| Type-erased task wrapper. More... | |
| struct | Aleph::ThreadPool::Task< F > |
| Concrete task implementation with type preservation. More... | |
| class | Aleph::TaskGroup |
| Minimal structured-concurrency helper over ThreadPool futures. More... | |
Namespaces | |
| namespace | Aleph |
| Main namespace for Aleph-w library functions. | |
| namespace | Aleph::cancellation_detail |
| namespace | Aleph::parallel_detail |
Typedefs | |
| using | Aleph::ExceptionCallback = std::function< void(std::exception_ptr)> |
| Type for exception callback in detached tasks. | |
Functions | |
| ThreadPool & | Aleph::default_pool () |
| Return the default shared thread pool instance. | |
| ThreadPool & | Aleph::parallel_detail::select_pool (const ParallelOptions &options) |
| size_t | Aleph::parallel_detail::resolve_chunk_size (const size_t total, const size_t num_threads, const ParallelOptions &options, const size_t min_chunk=1) |
| bool | Aleph::parallel_detail::use_sequential_path (const size_t total, const ThreadPool &pool, const ParallelOptions &options) noexcept |
| void | Aleph::parallel_detail::throw_if_canceled (const CancellationToken &token) |
| template<typename InputIt1 , typename InputIt2 , typename OutputIt , typename Compare > | |
| void | Aleph::parallel_detail::merge_sequential (InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first, Compare comp, const CancellationToken &token) |
| template<typename Iterator , typename F > | |
| void | Aleph::parallel_for (ThreadPool &pool, Iterator begin, Iterator end, F &&f, size_t chunk_size=0) |
| Execute a function in parallel over a range. | |
| template<typename Iterator , typename F > | |
| void | Aleph::parallel_for (Iterator begin, Iterator end, F &&f, const ParallelOptions &options={}) |
| Execute a function in parallel over a range with explicit options. | |
| template<typename InputIt , typename OutputIt , typename F > | |
| OutputIt | Aleph::parallel_transform (ThreadPool &pool, InputIt first, InputIt last, OutputIt d_first, F &&f, size_t chunk_size=0) |
| Transform elements in parallel and store results. | |
| template<typename InputIt , typename OutputIt , typename F > | |
| OutputIt | Aleph::parallel_transform (InputIt first, InputIt last, OutputIt d_first, F &&f, const ParallelOptions &options={}) |
| Parallel transform with explicit options. | |
| template<typename Iterator , typename T , typename BinaryOp > | |
| T | Aleph::parallel_reduce (ThreadPool &pool, Iterator first, Iterator last, T init, BinaryOp op, size_t chunk_size=0) |
| Reduce elements in parallel. | |
| template<typename Iterator , typename T , typename BinaryOp > | |
| T | Aleph::parallel_reduce (Iterator first, Iterator last, T init, BinaryOp op, const ParallelOptions &options={}) |
| Parallel reduce with explicit options. | |
| template<typename F > | |
| void | Aleph::parallel_for_index (ThreadPool &pool, size_t start, size_t end, F &&f, size_t chunk_size=0) |
| Apply a function to each element in parallel (index-based). | |
| template<typename F > | |
| void | Aleph::parallel_for_index (size_t start, size_t end, F &&f, const ParallelOptions &options={}) |
| Parallel index loop with explicit options. | |
| template<typename... Fs> | |
| void | Aleph::parallel_invoke (ThreadPool &pool, Fs &&... fs) |
| Invoke a small set of related callables in parallel. | |
| template<typename... Fs> | |
| void | Aleph::parallel_invoke (const ParallelOptions &options, Fs &&... fs) |
| parallel_invoke with explicit options. | |
| template<typename InputIt , typename OutputIt , typename BinaryOp > | |
| OutputIt | Aleph::pscan (ThreadPool &pool, InputIt first, InputIt last, OutputIt d_first, BinaryOp op, size_t chunk_size=0) |
| Inclusive prefix scan over a range. | |
| template<typename InputIt , typename OutputIt , typename BinaryOp > | |
| OutputIt | Aleph::pscan (InputIt first, InputIt last, OutputIt d_first, BinaryOp op, const ParallelOptions &options={}) |
| Inclusive prefix scan with explicit options. | |
| template<typename InputIt , typename OutputIt , typename T , typename BinaryOp > | |
| OutputIt | Aleph::pexclusive_scan (ThreadPool &pool, InputIt first, InputIt last, OutputIt d_first, T init, BinaryOp op, size_t chunk_size=0) |
| Exclusive prefix scan over a range. | |
| template<typename InputIt , typename OutputIt , typename T , typename BinaryOp > | |
| OutputIt | Aleph::pexclusive_scan (InputIt first, InputIt last, OutputIt d_first, T init, BinaryOp op, const ParallelOptions &options={}) |
| Exclusive prefix scan with explicit options. | |
| template<typename InputIt1 , typename InputIt2 , typename OutputIt , typename Compare = std::less<>> | |
| OutputIt | Aleph::pmerge (ThreadPool &pool, InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first, Compare comp=Compare{}, size_t chunk_size=0) |
| Merge two sorted ranges in parallel. | |
| template<typename InputIt1 , typename InputIt2 , typename OutputIt , typename Compare = std::less<>> | |
| OutputIt | Aleph::pmerge (InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first, Compare comp=Compare{}, const ParallelOptions &options={}) |
| Parallel merge with explicit options. | |
A modern, efficient thread pool for parallel task execution.
This file provides a reusable thread pool that maintains a fixed number of worker threads, avoiding the overhead of creating new threads for each task (as happens with std::async).
std::future<T> for result retrievalstd::invoke| Method | Overhead per task |
|---|---|
std::async | 10-100 μs (thread creation) |
ThreadPool | ~50-100 ns (queue + notify) |
std::functionstd::bind expressionsenqueue() and enqueue_detached() are thread-saferesize() and shutdown() should not be called concurrently with each otherDefinition in file thread_pool.H.