ThreadSchedule 2.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
threadschedule.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "chaos.hpp"
4#include "concepts.hpp"
5#include "error_handler.hpp"
6#include "futures.hpp"
7#include "generator.hpp"
8#include "profiles.hpp"
9#include "pthread_wrapper.hpp"
10#include "scheduled_pool.hpp"
11#include "scheduler_policy.hpp"
12#include "task.hpp"
13#include "thread_pool.hpp"
15#include "thread_registry.hpp"
16#include "thread_wrapper.hpp"
17#include "topology.hpp"
18
35
36namespace threadschedule
37{
38
42namespace ts = threadschedule;
43
44// Re-export main types for convenience
45#ifndef _WIN32
47#endif
50using ts::ChaosConfig;
52using ts::CpuTopology;
60using ts::GlobalPool;
77using ts::TaskError;
80using ts::ThreadPool;
83using ts::PollingWait;
91
92// Build-mode introspection
93using ts::BuildMode;
94using ts::build_mode;
96
97// Future combinators
98using ts::when_all;
100using ts::when_any;
101
102// Coroutine primitives (C++20)
103#if defined(__cpp_impl_coroutine) && __cpp_impl_coroutine >= 201902L
104using ts::executor_base;
105using ts::generator;
106using ts::pool_executor;
107using ts::run_on;
108using ts::schedule_on;
109using ts::sync_wait;
110using ts::task;
111#endif
112
113} // namespace threadschedule
Test/chaos features to perturb scheduling at runtime.
RAII controller that periodically perturbs scheduling attributes of registered threads for chaos/fuzz...
Definition chaos.hpp:86
Central registry and dispatcher for task-error callbacks.
A move-only future wrapper that supports an error callback.
Singleton accessor for a process-wide pool instance.
High-performance thread pool optimized for high-frequency task submission.
Ultra-lightweight fire-and-forget thread pool.
RAII wrapper around POSIX threads with a modern C++ interface.
Thread pool wrapper that combines any pool type with an ErrorHandler.
Copyable handle for a cancellable scheduled task.
Thread pool augmented with delayed and periodic task scheduling.
Manages a set of CPU indices to which a thread may be bound.
Looks up an OS thread by its name via /proc and provides scheduling control.
Single-queue thread pool parameterized by its idle-wait strategy.
Value-semantic wrapper for a thread scheduling priority.
Non-owning view over an externally managed std::thread.
Owning wrapper around std::thread with RAII join-on-destroy semantics.
C++20 concepts, type traits, and SFINAE helpers for the threading library.
Error handling primitives: TaskError, ErrorHandler, and ErrorHandledTask.
Combinators for std::future: when_all, when_any, when_all_settled.
Lazy multi-value coroutine (generator<T>).
SchedulingPolicy
Enumeration of available thread scheduling policies.
PoolWithErrors< FastThreadPool > FastThreadPoolWithErrors
FastThreadPool with integrated error handling.
ShutdownPolicy
Controls how a pool handles pending tasks during shutdown.
ThreadPoolBase< IndefiniteWait > ThreadPool
General-purpose thread pool with indefinite blocking wait.
auto apply_profile(ThreadLike &t, ThreadProfile const &p) -> expected< void, std::error_code >
Apply a profile to a thread wrapper or view.
Definition profiles.hpp:160
BuildMode
Indicates whether the library was compiled in header-only or runtime (shared library) mode.
auto affinity_for_node(int node_index, int thread_index, int threads_per_node=1) -> ThreadAffinity
Build a ThreadAffinity for the given NUMA node.
Definition topology.hpp:151
auto distribute_affinities_by_numa(size_t num_threads) -> std::vector< ThreadAffinity >
Distribute thread affinities across NUMA nodes in round-robin order.
Definition topology.hpp:182
GlobalPool< ThreadPool > GlobalThreadPool
Singleton accessor for the process-wide ThreadPool instance.
ThreadWrapperView JThreadWrapperView
ScheduledThreadPoolT< ThreadPool > ScheduledThreadPool
ScheduledThreadPoolT using the default ThreadPool backend.
ThreadPoolBase< PollingWait<> > FastThreadPool
Thread pool with 10 ms polling wait for lower wake-up latency.
PoolWithErrors< ThreadPool > ThreadPoolWithErrors
ThreadPool with integrated error handling.
GlobalPool< HighPerformancePool > GlobalHighPerformancePool
Singleton accessor for the process-wide HighPerformancePool instance.
ScheduledThreadPoolT< FastThreadPool > ScheduledFastThreadPool
ScheduledThreadPoolT using FastThreadPool as backend.
PoolWithErrors< HighPerformancePool > HighPerformancePoolWithErrors
HighPerformancePool with integrated error handling.
ScheduledThreadPoolT< LightweightPool > ScheduledLightweightPool
ScheduledThreadPoolT using LightweightPool as backend (minimal overhead).
std::function< void(std::chrono::steady_clock::time_point, std::thread::id, std::chrono::microseconds elapsed)> TaskEndCallback
Callback invoked when a pool worker finishes executing a task.
auto build_mode_string() -> char const *
Returns a human-readable C string describing the active build mode.
auto when_all(std::vector< std::future< T > > &futures) -> std::vector< T >
Block until all futures complete, returning results in submission order.
Definition futures.hpp:34
std::function< void(TaskError const &)> ErrorCallback
Signature for error-handling callbacks registered with ErrorHandler.
std::function< void(std::chrono::steady_clock::time_point, std::thread::id)> TaskStartCallback
Work-stealing deque for per-thread task queues in a thread pool.
ScheduledThreadPoolT< HighPerformancePool > ScheduledHighPerformancePool
ScheduledThreadPoolT using HighPerformancePool as backend.
auto when_all_settled(std::vector< std::future< T > > &futures) -> std::vector< expected< T, std::exception_ptr > >
Block until all futures complete, returning an expected per slot.
Definition futures.hpp:95
auto when_any(std::vector< std::future< T > > &futures) -> std::pair< size_t, T >
Block until the first future becomes ready.
Definition futures.hpp:154
ThreadWrapper JThreadWrapper
Owning wrapper around std::jthread with cooperative cancellation (C++20).
auto read_topology() -> CpuTopology
Discover basic topology. Linux: reads /sys for NUMA nodes. Windows: single node, sequential CPU indic...
Definition topology.hpp:53
auto build_mode() -> BuildMode
Returns the build mode detected at compile time (header-only variant).
LightweightPoolT<> LightweightPool
Default lightweight pool with 64-byte task slots (56 bytes usable).
High-level thread configuration profiles and helpers.
RAII wrapper around POSIX threads (Linux only).
Delayed and periodic task scheduling on top of any pool type.
Scheduling policies, thread priority, and CPU affinity types.
Plain value type holding runtime chaos-testing parameters.
Definition chaos.hpp:34
Snapshot of basic CPU/NUMA topology.
Definition topology.hpp:39
Wait policy that polls with a configurable timeout.
Holds diagnostic information captured from a failed task.
Declarative profile bundling scheduling intent for a thread.
Definition profiles.hpp:57
Coroutine task, sync_wait, and pool helpers schedule_on / run_on.
Thread pools: HighPerformancePool, ThreadPoolBase, LightweightPoolT, and GlobalPool.
PoolWithErrors wrapper that combines any pool with an ErrorHandler.
Process-wide thread registry, control blocks, and composite registry.
Enhanced thread wrappers: ThreadWrapper, JThreadWrapper, and non-owning views.
Hardware topology helpers (CPU count, NUMA nodes) and affinity builders.