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
Public Functions
Section titled “Public Functions”| Name | |
|---|---|
| ~RoundRobinScheduler() override =default | |
| virtual ScheduleResult | selectNextGroup(const std::vector< WorkContractGroup * > & groups) override Selects next group in round-robin order. |
| virtual void | reset() override Resets thread-local rotation index to 0. |
| virtual void | notifyWorkExecuted(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. |
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 | notifyGroupsChanged(const std::vector< WorkContractGroup * > & newGroups) Notifies scheduler that the group list has changed. |
Detailed Description
Section titled “Detailed Description”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 workfor (auto& group : groups) { for (int i = 0; i < 100; ++i) { auto handle = group->createContract(work); handle.schedule(); }}
// Use round-robin for predictable executionauto scheduler = std::make_unique<RoundRobinScheduler>(config);WorkService service(wsConfig, std::move(scheduler));Public Functions Documentation
Section titled “Public Functions Documentation”function ~RoundRobinScheduler
Section titled “function ~RoundRobinScheduler”~RoundRobinScheduler() override =defaultfunction selectNextGroup
Section titled “function selectNextGroup”virtual ScheduleResult selectNextGroup( const std::vector< WorkContractGroup * > & groups) overrideSelects 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)function reset
Section titled “function reset”virtual void reset() overrideResets thread-local rotation index to 0.
Reimplements: EntropyEngine::Core::Concurrency::IWorkScheduler::reset
Only affects calling thread. Others reset on next schedule.
function notifyWorkExecuted
Section titled “function notifyWorkExecuted”inline virtual void notifyWorkExecuted( WorkContractGroup * group, size_t threadId) overrideNo-op - round-robin doesn’t track execution history.
Reimplements: EntropyEngine::Core::Concurrency::IWorkScheduler::notifyWorkExecuted
function getName
Section titled “function getName”inline virtual const char * getName() const overrideReturns “RoundRobin”.
Reimplements: EntropyEngine::Core::Concurrency::IWorkScheduler::getName
function RoundRobinScheduler
Section titled “function RoundRobinScheduler”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