ThreadSchedule 2.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
thread_pool.hpp File Reference

Thread pools: HighPerformancePool, ThreadPoolBase, LightweightPoolT, and GlobalPool. More...

#include "expected.hpp"
#include "scheduler_policy.hpp"
#include "thread_registry.hpp"
#include "thread_wrapper.hpp"
#include <algorithm>
#include <array>
#include <atomic>
#include <condition_variable>
#include <cstddef>
#include <cstdint>
#include <future>
#include <mutex>
#include <optional>
#include <queue>
#include <random>
#include <tuple>
#include <vector>
Include dependency graph for thread_pool.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  threadschedule::detail::SboCallable< TaskSize >
 Type-erased, move-only callable with configurable inline storage. More...
class  threadschedule::WorkStealingDeque< T >
class  threadschedule::HighPerformancePool
 High-performance thread pool optimized for high-frequency task submission. More...
struct  threadschedule::HighPerformancePool::Statistics
struct  threadschedule::IndefiniteWait
 Wait policy that blocks indefinitely until work is available. More...
struct  threadschedule::PollingWait< IntervalMs >
 Wait policy that polls with a configurable timeout. More...
class  threadschedule::ThreadPoolBase< WaitPolicy >
 Single-queue thread pool parameterized by its idle-wait strategy. More...
struct  threadschedule::ThreadPoolBase< WaitPolicy >::Statistics
class  threadschedule::LightweightPoolT< TaskSize >
 Ultra-lightweight fire-and-forget thread pool. More...
class  threadschedule::GlobalPool< PoolType >
 Singleton accessor for a process-wide pool instance. More...

Namespaces

namespace  threadschedule
namespace  threadschedule::detail

Typedefs

using threadschedule::TaskStartCallback = std::function<void(std::chrono::steady_clock::time_point, std::thread::id)>
 Work-stealing deque for per-thread task queues in a thread pool.
using threadschedule::TaskEndCallback
 Callback invoked when a pool worker finishes executing a task.
using threadschedule::ThreadPool = ThreadPoolBase<IndefiniteWait>
 General-purpose thread pool with indefinite blocking wait.
using threadschedule::FastThreadPool = ThreadPoolBase<PollingWait<>>
 Thread pool with 10 ms polling wait for lower wake-up latency.
using threadschedule::LightweightPool = LightweightPoolT<>
 Default lightweight pool with 64-byte task slots (56 bytes usable).
using threadschedule::GlobalThreadPool = GlobalPool<ThreadPool>
 Singleton accessor for the process-wide ThreadPool instance.
using threadschedule::GlobalHighPerformancePool = GlobalPool<HighPerformancePool>
 Singleton accessor for the process-wide HighPerformancePool instance.

Enumerations

enum class  threadschedule::ShutdownPolicy : uint8_t { threadschedule::drain , threadschedule::drop_pending }
 Controls how a pool handles pending tasks during shutdown. More...

Functions

template<typename WorkerRange>
auto threadschedule::detail::configure_worker_threads (WorkerRange &workers, std::string const &name_prefix, SchedulingPolicy policy, ThreadPriority priority) -> expected< void, std::error_code >
template<typename WorkerRange>
auto threadschedule::detail::set_worker_affinity (WorkerRange &workers, ThreadAffinity const &affinity) -> expected< void, std::error_code >
template<typename WorkerRange>
auto threadschedule::detail::distribute_workers_across_cpus (WorkerRange &workers) -> expected< void, std::error_code >
template<typename Pool, typename Iterator, typename F>
void threadschedule::detail::parallel_for_each_chunked (Pool &pool, Iterator begin, Iterator end, F &&func, size_t num_workers)
template<typename F, typename... Args>
auto threadschedule::detail::bind_args (F &&f, Args &&... args)
 Bind a callable with its arguments into a nullary lambda.
template<typename Container, typename F>
void threadschedule::parallel_for_each (Container &container, F &&func)
 Convenience wrapper that applies a callable to every element of a container in parallel using the GlobalThreadPool singleton.

Detailed Description

Thread pools: HighPerformancePool, ThreadPoolBase, LightweightPoolT, and GlobalPool.

Definition in file thread_pool.hpp.