Skip to content

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

Name
~SpinningDirectScheduler() override =default
Destroys the scheduler.
virtual ScheduleResultselectNextGroup(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.

Public Classes inherited from EntropyEngine::Core::Concurrency::IWorkScheduler

Name
structScheduleResult
Result of a scheduling decision.
structConfig
Configuration for scheduler behavior.

Public Functions inherited from EntropyEngine::Core::Concurrency::IWorkScheduler

Name
virtual~IWorkScheduler() =default
virtual voidreset()
Resets scheduler to initial state.
virtual voidnotifyWorkExecuted(WorkContractGroup * group, size_t threadId)
Notifies scheduler that work was successfully executed.
virtual voidnotifyGroupsChanged(const std::vector< WorkContractGroup * > & newGroups)
Notifies scheduler that the group list has changed.
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 DirectScheduler
auto 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 overhead
~SpinningDirectScheduler() override =default

Destroys the scheduler.

inline virtual ScheduleResult selectNextGroup(
const std::vector< WorkContractGroup * > & groups
) override

Selects 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 DirectScheduler
auto 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...
}
inline virtual const char * getName() const override

Returns the scheduler’s name.

Return: “SpinningDirect”

Reimplements: EntropyEngine::Core::Concurrency::IWorkScheduler::getName

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 ignored
IWorkScheduler::Config config;
config.failureSleepTime = 1000000; // Ignored - threads will spin continuously
auto scheduler = std::make_unique<SpinningDirectScheduler>(config);

Updated on 2026-01-26 at 17:14:35 -0500