EntropyEngine::Core::Concurrency::SpinningDirectScheduler
EntropyEngine::Core::Concurrency::SpinningDirectScheduler
Section titled “EntropyEngine::Core::Concurrency::SpinningDirectScheduler”CPU-intensive scheduler that eliminates sleep/wake overhead for benchmarking. More…
#include <SpinningDirectScheduler.h>
Inherits from EntropyEngine::Core::Concurrency::IWorkScheduler
Public Functions
Section titled “Public Functions”| Name | |
|---|---|
| ~SpinningDirectScheduler() override =default Destroys the scheduler. | |
| virtual ScheduleResult | selectNextGroup(const std::vector< WorkContractGroup * > & groups) override Selects the first group with work, never sleeps. |
| virtual const char * | getName() const override Returns the scheduler’s name. |
| SpinningDirectScheduler(const Config & config) Creates a scheduler that maintains continuous thread activity. |
Additional inherited members
Section titled “Additional inherited members”Public Classes inherited from EntropyEngine::Core::Concurrency::IWorkScheduler
| Name | |
|---|---|
| struct | ScheduleResult Result of a scheduling decision. |
| struct | Config Configuration for scheduler behavior. |
Public Functions inherited from EntropyEngine::Core::Concurrency::IWorkScheduler
| Name | |
|---|---|
| virtual | ~IWorkScheduler() =default |
| virtual void | reset() Resets scheduler to initial state. |
| virtual void | notifyWorkExecuted(WorkContractGroup * group, size_t threadId) Notifies scheduler that work was successfully executed. |
| virtual void | notifyGroupsChanged(const std::vector< WorkContractGroup * > & newGroups) Notifies scheduler that the group list has changed. |
Detailed Description
Section titled “Detailed Description”class EntropyEngine::Core::Concurrency::SpinningDirectScheduler;CPU-intensive scheduler that eliminates sleep/wake overhead for benchmarking.
SpinningDirectScheduler extends the DirectScheduler concept by eliminating all thread sleep operations. While DirectScheduler allows threads to sleep when no work is available, this implementation maintains continuous CPU activity through spinning, even when work queues are empty.
Purpose: This scheduler specifically addresses the benchmarking requirement to measure and isolate thread sleep/wake overhead by providing a comparison baseline where such overhead is completely eliminated.
Characteristics:
- CPU usage when idle: 100% per thread
- No thread sleep/wake cycles
- Threads remain active continuously
Recommended use cases:
- Diagnosing impact of OS thread scheduling
- Measuring sleep/wake cycle overhead in workloads
- Testing scenarios requiring minimal latency
- Comparative benchmarking against DirectScheduler
Not recommended for:
- Production systems (excessive CPU consumption)
- Battery-powered devices (rapid power drain)
- Shared computing environments (resource monopolization)
- Any scenario requiring power efficiency
Benchmarking insight: Comparing this scheduler against DirectScheduler reveals OS-specific thread wake latencies, which vary significantly by operating system and system load.
// Use this to compare against DirectSchedulerauto directScheduler = std::make_unique<DirectScheduler>(config);WorkService directService(config, std::move(directScheduler));// Run benchmark...
auto spinningScheduler = std::make_unique<SpinningDirectScheduler>(config);WorkService spinningService(config, std::move(spinningScheduler));// Run same benchmark...
// The difference in execution time = thread wake overheadPublic Functions Documentation
Section titled “Public Functions Documentation”function ~SpinningDirectScheduler
Section titled “function ~SpinningDirectScheduler”~SpinningDirectScheduler() override =defaultDestroys the scheduler.
function selectNextGroup
Section titled “function selectNextGroup”inline virtual ScheduleResult selectNextGroup( const std::vector< WorkContractGroup * > & groups) overrideSelects the first group with work, never sleeps.
Parameters:
- groups List of work groups to check
- context Thread context (ignored)
Return: First group with work, or {nullptr, false} to keep spinning
Reimplements: EntropyEngine::Core::Concurrency::IWorkScheduler::selectNextGroup
Like DirectScheduler but shouldSleep is ALWAYS false. Keeps threads spinning to maintain CPU cache residency at cost of cycles.
// When there's work, behaves like DirectSchedulerauto result = scheduler->selectNextGroup(groups, context);if (result.group) { // Execute work from result.group} else { // No work, but result.shouldSleep is false // Thread will immediately call selectNextGroup again // CPU core temperature increases...}function getName
Section titled “function getName”inline virtual const char * getName() const overrideReturns the scheduler’s name.
Return: “SpinningDirect”
Reimplements: EntropyEngine::Core::Concurrency::IWorkScheduler::getName
function SpinningDirectScheduler
Section titled “function SpinningDirectScheduler”inline explicit SpinningDirectScheduler( const Config & config)Creates a scheduler that maintains continuous thread activity.
Parameters:
- config Accepted for interface compatibility but unused
Config is ignored - always operates in continuous spinning mode.
// Configuration parameters are ignoredIWorkScheduler::Config config;config.failureSleepTime = 1000000; // Ignored - threads will spin continuouslyauto scheduler = std::make_unique<SpinningDirectScheduler>(config);Updated on 2026-01-26 at 17:14:35 -0500