|
Aleph-w 3.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 <condition_variable>#include <atomic>#include <vector>#include <thread>#include <mutex>#include <stdexcept>#include <type_traits>#include <tuple>#include <memory>#include <limits>#include <optional>#include <chrono>#include <numeric>#include <iterator>Go to the source code of this file.
Classes | |
| 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... | |
Namespaces | |
| namespace | Aleph |
| Main namespace for Aleph-w library functions. | |
Typedefs | |
| using | Aleph::ExceptionCallback = std::function< void(std::exception_ptr)> |
| Type for exception callback in detached tasks. | |
Functions | |
| 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 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 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 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). | |
| ThreadPool & | Aleph::default_pool () |
| Global default thread pool. | |
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.