ThreadSchedule 3.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
threadschedule::advanced Namespace Reference

Namespaces

namespace  error_handler_detail
 
namespace  profile_detail
 
namespace  profiles
 
namespace  topology_detail
 

Classes

struct  chaos_config
 
class  chaos_controller
 
class  composite_thread_registry
 Non-owning facade that merges snapshots from multiple registries. More...
 
struct  cpu_topology
 Snapshot of basic CPU/NUMA topology. More...
 
class  error_handled_task
 Callable wrapper that catches exceptions and routes them to an error_handler. More...
 
class  error_handler
 Central registry and dispatcher for task-error callbacks. More...
 
class  future_with_error_handler
 A move-only future wrapper that supports an error callback. More...
 
class  global_thread_pool
 
class  global_work_stealing_pool
 
class  inline_pool
 
class  lightweight_pool
 
class  polling_pool
 
class  raw_scheduled_pool
 
class  raw_thread_pool
 
class  scheduled_lightweight_pool
 
class  scheduled_polling_pool
 
class  scheduled_work_stealing_pool
 
class  task_group
 Scoped task group that ensures all submitted work completes before the group is destroyed. More...
 
class  thread_by_name_view
 Non-owning control view found by an exact process-thread name. More...
 
struct  thread_profile
 
class  work_stealing_pool
 

Typedefs

using native_thread_id = pid_t
 

Functions

auto cgroup_attach_tid (std::string const &cgroup_dir, native_thread_id tid) -> result< void >
 Attach a native Linux thread ID to a cgroup v1 or v2 directory.
 
auto read_topology () -> cpu_topology
 Discover basic topology. Linux: reads /sys for NUMA nodes. Windows: single node, processor-group-aware CPU indices.
 
auto affinity_for_node (cpu_topology const &topo, int node_index, int thread_index, int threads_per_node=1) -> thread_affinity
 Build a thread_affinity for the given NUMA node using a pre-read topology.
 
auto affinity_for_node (int node_index, int thread_index, int threads_per_node=1) -> thread_affinity
 Build a thread_affinity for the given NUMA node.
 
auto distribute_affinities_by_numa (cpu_topology const &topo, size_t num_threads) -> std::vector< thread_affinity >
 Distribute thread affinities across NUMA nodes in round-robin order.
 
auto distribute_affinities_by_numa (size_t num_threads) -> std::vector< thread_affinity >
 Distribute thread affinities across NUMA nodes in round-robin order.
 
template<typename Func >
auto make_error_handled_task (Func &&func, std::shared_ptr< error_handler > handler, std::string description="")
 Factory function that creates an error_handled_task with perfect forwarding.
 
template<typename T >
auto when_all (std::vector< std::future< T > > &futures) -> std::vector< T >
 Block until all futures complete, returning results in submission order.
 
void when_all (std::vector< std::future< void > > &futures)
 Block until all void futures complete.
 
template<typename T >
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.
 
auto when_all_settled (std::vector< std::future< void > > &futures) -> std::vector< expected< void, std::exception_ptr > >
 Block until all void futures complete, returning an expected per slot.
 
template<typename T >
auto when_any (std::vector< std::future< T > > &futures) -> std::pair< size_t, T >
 Block until the first future becomes ready.
 
auto when_any (std::vector< std::future< void > > &futures) -> size_t
 Block until the first void future becomes ready.
 
auto native_handle (thread &value) -> std::thread::native_handle_type
 
auto native_id (thread_id id) noexcept -> result< native_thread_id >
 
template<typename ThreadLike >
auto apply_profile (ThreadLike &value, thread_profile const &profile) -> result< void >
 
auto apply_profile (raw_thread_pool &pool, thread_profile const &profile) -> result< void >
 
auto apply_profile (polling_pool &pool, thread_profile const &profile) -> result< void >
 
auto apply_profile (work_stealing_pool &pool, thread_profile const &profile) -> result< void >
 
template<typename ThreadLike >
auto apply_profile_detailed (ThreadLike &value, thread_profile const &profile) -> std::vector< std::error_code >
 

Typedef Documentation

◆ native_thread_id

Definition at line 61 of file native_thread.hpp.

Function Documentation

◆ affinity_for_node() [1/2]

auto threadschedule::advanced::affinity_for_node ( cpu_topology const &  topo,
int  node_index,
int  thread_index,
int  threads_per_node = 1 
) -> thread_affinity
inline

Build a thread_affinity for the given NUMA node using a pre-read topology.

Parameters
topoPre-read topology snapshot.
node_indexNUMA node index (wraps if out of range).
thread_indexUsed to select CPU(s) within the node.
threads_per_nodeNumber of CPUs to include per thread (default 1).

Definition at line 210 of file cpu_topology.hpp.

References threadschedule::thread_affinity::add_cpu().

Referenced by affinity_for_node(), and distribute_affinities_by_numa().

◆ affinity_for_node() [2/2]

auto threadschedule::advanced::affinity_for_node ( int  node_index,
int  thread_index,
int  threads_per_node = 1 
) -> thread_affinity
inline

Build a thread_affinity for the given NUMA node.

Calls read_topology() internally on every invocation (no caching).

Parameters
node_indexNUMA node index (wraps if out of range).
thread_indexUsed to select CPU(s) within the node.
threads_per_nodeNumber of CPUs to include per thread (default 1).

Definition at line 252 of file cpu_topology.hpp.

References affinity_for_node(), and read_topology().

◆ apply_profile() [1/4]

auto threadschedule::advanced::apply_profile ( polling_pool pool,
thread_profile const &  profile 
) -> result<void>
inline

◆ apply_profile() [2/4]

auto threadschedule::advanced::apply_profile ( raw_thread_pool pool,
thread_profile const &  profile 
) -> result<void>
inline

◆ apply_profile() [3/4]

template<typename ThreadLike >
auto threadschedule::advanced::apply_profile ( ThreadLike &  value,
thread_profile const &  profile 
) -> result<void>

◆ apply_profile() [4/4]

auto threadschedule::advanced::apply_profile ( work_stealing_pool pool,
thread_profile const &  profile 
) -> result<void>
inline

◆ apply_profile_detailed()

template<typename ThreadLike >
auto threadschedule::advanced::apply_profile_detailed ( ThreadLike &  value,
thread_profile const &  profile 
) -> std::vector<std::error_code>

Definition at line 108 of file thread_profile.hpp.

References threadschedule::thread_config::set_name().

◆ cgroup_attach_tid()

auto threadschedule::advanced::cgroup_attach_tid ( std::string const &  cgroup_dir,
native_thread_id  tid 
) -> result<void>
inline

Attach a native Linux thread ID to a cgroup v1 or v2 directory.

Returns
Success, or operation_not_permitted when no supported control file can be written.

Definition at line 25 of file cgroup.hpp.

◆ distribute_affinities_by_numa() [1/2]

auto threadschedule::advanced::distribute_affinities_by_numa ( cpu_topology const &  topo,
size_t  num_threads 
) -> std::vector<thread_affinity>
inline

Distribute thread affinities across NUMA nodes in round-robin order.

Uses a pre-read topology to avoid repeated sysfs access.

Parameters
topoPre-read topology snapshot.
num_threadsNumber of affinity masks to generate.
Returns
Vector of num_threads thread_affinity objects.

Definition at line 267 of file cpu_topology.hpp.

References affinity_for_node().

Referenced by distribute_affinities_by_numa().

◆ distribute_affinities_by_numa() [2/2]

auto threadschedule::advanced::distribute_affinities_by_numa ( size_t  num_threads) -> std::vector<thread_affinity>
inline

Distribute thread affinities across NUMA nodes in round-robin order.

Returns one thread_affinity per thread, cycling through NUMA nodes so that consecutive threads are spread across different nodes.

Parameters
num_threadsNumber of affinity masks to generate.
Returns
Vector of num_threads thread_affinity objects.

Definition at line 289 of file cpu_topology.hpp.

References distribute_affinities_by_numa(), and read_topology().

◆ make_error_handled_task()

template<typename Func >
auto threadschedule::advanced::make_error_handled_task ( Func &&  func,
std::shared_ptr< error_handler handler,
std::string  description = "" 
)

Factory function that creates an error_handled_task with perfect forwarding.

Template Parameters
FuncCallable type (deduced).
Parameters
funcThe callable to wrap.
handlerShared pointer to the error_handler that will receive errors.
descriptionOptional human-readable label stored in task_error::task_description.
Returns
An error_handled_task containing a decayed copy of func.

Definition at line 257 of file error_handler.hpp.

◆ native_handle()

auto threadschedule::advanced::native_handle ( thread value) -> std::thread::native_handle_type
inline

Definition at line 45 of file native_thread.hpp.

◆ native_id()

auto threadschedule::advanced::native_id ( thread_id  id) -> result<native_thread_id>
inlinenoexcept

◆ read_topology()

auto threadschedule::advanced::read_topology ( ) -> cpu_topology
inline

Discover basic topology. Linux: reads /sys for NUMA nodes. Windows: single node, processor-group-aware CPU indices.

Called frequently by chaos/affinity helpers. The result is not cached internally - consider caching the returned cpu_topology yourself if performance of repeated calls matters.

Definition at line 123 of file cpu_topology.hpp.

References threadschedule::advanced::cpu_topology::cpu_count, threadschedule::advanced::cpu_topology::node_to_cpus, threadschedule::advanced::cpu_topology::numa_nodes, and threadschedule::advanced::topology_detail::read_index_list().

Referenced by affinity_for_node(), and distribute_affinities_by_numa().

◆ when_all() [1/2]

template<typename T >
auto threadschedule::advanced::when_all ( std::vector< std::future< T > > &  futures) -> std::vector<T>

Block until all futures complete, returning results in submission order.

If any future throws, the first exception is captured and re-thrown after all remaining futures have been waited on (to avoid leaving them dangling).

Template Parameters
TThe value type of each future.
Parameters
futuresA vector of futures to wait on. Moved-from on return.
Returns
A vector of values in the same order as the input futures.

Definition at line 39 of file futures.hpp.

◆ when_all() [2/2]

void threadschedule::advanced::when_all ( std::vector< std::future< void > > &  futures)
inline

Block until all void futures complete.

Re-throws the first exception after all futures have been waited on.

Definition at line 70 of file futures.hpp.

◆ when_all_settled() [1/2]

template<typename T >
auto threadschedule::advanced::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.

Never throws. Each slot is either the result value or the captured std::exception_ptr.

Template Parameters
TThe value type of each future.

Definition at line 101 of file futures.hpp.

◆ when_all_settled() [2/2]

auto threadschedule::advanced::when_all_settled ( std::vector< std::future< void > > &  futures) -> std::vector<expected<void, std::exception_ptr>>
inline

Block until all void futures complete, returning an expected per slot.

Definition at line 126 of file futures.hpp.

◆ when_any() [1/2]

template<typename T >
auto threadschedule::advanced::when_any ( std::vector< std::future< T > > &  futures) -> std::pair<size_t, T>

Block until the first future becomes ready.

Polls all futures round-robin with a 1 ms timeout until one is ready, then returns its index and value.

Note
The remaining futures are left in their current state - the caller is responsible for managing their lifetime.
A deferred future is eligible immediately and is executed by the calling thread through get().
Template Parameters
TThe value type of each future.
Returns
A pair of (index of the first ready future, its value).

Definition at line 163 of file futures.hpp.

◆ when_any() [2/2]

auto threadschedule::advanced::when_any ( std::vector< std::future< void > > &  futures) -> size_t
inline

Block until the first void future becomes ready.

Returns
The index of the first ready future.
Exceptions
std::invalid_argumentIf futures is empty.

Definition at line 200 of file futures.hpp.