ThreadSchedule 2.2.0
Modern C++ thread management library
Loading...
Searching...
No Matches
threadschedule::ChaosController Class Reference

RAII controller that periodically perturbs scheduling attributes of registered threads for chaos/fuzz testing. More...

#include <chaos.hpp>

Public Member Functions

template<typename Predicate>
 ChaosController (ChaosConfig cfg, Predicate pred)
 ~ChaosController ()
 ChaosController (ChaosController const &)=delete
auto operator= (ChaosController const &) -> ChaosController &=delete
auto thread_info () const -> std::optional< ThreadInfo >
auto configure_thread (std::string const &name, SchedulingPolicy policy=SchedulingPolicy::OTHER, ThreadPriority priority=ThreadPriority::normal()) -> expected< void, std::error_code >

Detailed Description

RAII controller that periodically perturbs scheduling attributes of registered threads for chaos/fuzz testing.

On construction, ChaosController spawns a background control thread that wakes every ChaosConfig::interval and applies perturbations (affinity shuffling, priority jitter) to threads in the global registry() that match the user-supplied predicate.

Ownership semantics:

  • Non-copyable, non-movable.
  • The destructor signals the worker to stop and blocks until it joins. Do not destroy from a context where blocking is unacceptable.

Thread safety: The controller operates on the global registry(), which is internally synchronized, so multiple controllers or concurrent registrations are safe.

Warning
Intended for testing and validation only - not for production use. Perturbations may cause spurious priority inversions and cache-thrashing.
Example
ChaosConfig cfg{.interval = 100ms, .priority_jitter = 5};
ChaosController chaos(cfg, [](auto const& info) {
return info.name.starts_with("worker");
});
// ... run tests while chaos is active ...
// destructor joins the worker thread
RAII controller that periodically perturbs scheduling attributes of registered threads for chaos/fuzz...
Definition chaos.hpp:87
Plain value type holding runtime chaos-testing parameters.
Definition chaos.hpp:35
See also
ChaosConfig, registry()

Definition at line 86 of file chaos.hpp.

Constructor & Destructor Documentation

◆ ChaosController() [1/2]

template<typename Predicate>
threadschedule::ChaosController::ChaosController ( ChaosConfig cfg,
Predicate pred )
inline

◆ ~ChaosController()

threadschedule::ChaosController::~ChaosController ( )
inline

Definition at line 104 of file chaos.hpp.

◆ ChaosController() [2/2]

threadschedule::ChaosController::ChaosController ( ChaosController const & )
delete

References ChaosController().

Member Function Documentation

◆ configure_thread()

auto threadschedule::ChaosController::configure_thread ( std::string const & name,
SchedulingPolicy policy = SchedulingPolicy::OTHER,
ThreadPriority priority = ThreadPriority::normal() ) -> expected<void, std::error_code>
inline

◆ operator=()

auto threadschedule::ChaosController::operator= ( ChaosController const & ) -> ChaosController &=delete
delete

References ChaosController().

◆ thread_info()

auto threadschedule::ChaosController::thread_info ( ) const -> std::optional<ThreadInfo>
inlinenodiscard

Definition at line 114 of file chaos.hpp.

Referenced by configure_thread().


The documentation for this class was generated from the following file: