Skip to content

EntropyEngine::Core::Concurrency::RoundRobinScheduler

EntropyEngine::Core::Concurrency::RoundRobinScheduler

Section titled “EntropyEngine::Core::Concurrency::RoundRobinScheduler”

Fair round-robin scheduler providing uniform work distribution. More…

#include <RoundRobinScheduler.h>

Inherits from EntropyEngine::Core::Concurrency::IWorkScheduler

Name
~RoundRobinScheduler() override =default
virtual ScheduleResultselectNextGroup(const std::vector< WorkContractGroup * > & groups) override
Selects next group in round-robin order.
virtual voidreset() override
Resets thread-local rotation index to 0.
virtual voidnotifyWorkExecuted(WorkContractGroup * group, size_t threadId) override
No-op - round-robin doesn’t track execution history.
virtual const char *getName() const override
Returns “RoundRobin”.
RoundRobinScheduler(const Config & config)
Constructs round-robin scheduler.

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 voidnotifyGroupsChanged(const std::vector< WorkContractGroup * > & newGroups)
Notifies scheduler that the group list has changed.
class EntropyEngine::Core::Concurrency::RoundRobinScheduler;

Fair round-robin scheduler providing uniform work distribution.

RoundRobinScheduler implements a simple circular scheduling strategy where each thread cycles through work groups in sequential order. Upon reaching the last group, the scheduler wraps back to the first, ensuring equal opportunity for all groups. This approach prioritizes fairness and simplicity over adaptive optimization.

Advantages:

  • Simple implementation facilitates understanding and debugging
  • Provides perfect fairness with equal execution opportunities
  • No complex calculations or state management
  • Zero contention through thread-local counter implementation

Limitations:

  • No empty group detection (cycles through all groups regardless of work availability)
  • Disregards cache locality (threads alternate between groups)
  • Cannot adapt to workload imbalances (uniform treatment of all groups)

Recommended use cases:

  • Workloads with similar work distribution across groups
  • Systems requiring predictable, deterministic scheduling behavior
  • Debugging scenarios where scheduler variability must be eliminated
  • Applications prioritizing fairness over throughput

Not recommended when:

  • Significant work imbalances exist between groups
  • Work arrives in bursts to specific groups
  • Cache locality is important
// Perfect for evenly distributed work
for (auto& group : groups) {
for (int i = 0; i < 100; ++i) {
auto handle = group->createContract(work);
handle.schedule();
}
}
// Use round-robin for predictable execution
auto scheduler = std::make_unique<RoundRobinScheduler>(config);
WorkService service(wsConfig, std::move(scheduler));
~RoundRobinScheduler() override =default
virtual ScheduleResult selectNextGroup(
const std::vector< WorkContractGroup * > & groups
) override

Selects next group in round-robin order.

Parameters:

  • groups Available work groups
  • context Current thread context (ignored)

Return: Next group with work, or nullptr if none

Reimplements: EntropyEngine::Core::Concurrency::IWorkScheduler::selectNextGroup

Starts where we left off, checks each group for work. Each thread maintains its own position - no synchronization needed.

// What actually happens inside:
// 1. Get this thread's current position
// 2. Loop through all groups starting from that position
// 3. First group with scheduledCount() > 0 wins
// 4. Update position for next time
// 5. Return the winner (or nullptr)
virtual void reset() override

Resets thread-local rotation index to 0.

Reimplements: EntropyEngine::Core::Concurrency::IWorkScheduler::reset

Only affects calling thread. Others reset on next schedule.

inline virtual void notifyWorkExecuted(
WorkContractGroup * group,
size_t threadId
) override

No-op - round-robin doesn’t track execution history.

Reimplements: EntropyEngine::Core::Concurrency::IWorkScheduler::notifyWorkExecuted

inline virtual const char * getName() const override

Returns “RoundRobin”.

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

explicit RoundRobinScheduler(
const Config & config
)

Constructs round-robin scheduler.

Parameters:

  • config Scheduler configuration (unused)

Config is unused - round-robin needs no tuning.


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