Introduction
The best way to understand how scheduler works is to implement our own scheduler and processor simulation (Source Code On Github).
The following details my attempt to implement scheduler simulation with three components
- Input Stream - represents IO
- Scheduler - maintains a buffer of ready tasks, apply scheduling strategy to choose a task, and schedule it for execution
- Processor - wait for scheduler to schedule and execute tasks
Some other important constructs are
ctx context.WithTimeout()the same context is propagated across different go routines to help identify deadlocks.var systemTime atomic.Int32is used to synchronise task timing across the routinesvar ExecStatshelp with logging and visualisation.
Code Design

Todo
Current implementation needs the following improvement
- Calculate response time in addition to turnaround time
- Verify if the existing architecture can support task switching