Round Robin Scheduler
Round Robin Scheduler
Simulate a round robin scheduler with context switch overhead.
Types
type Task struct {
ID int
Arrival int
Burst int
}
type Result struct {
Completion map[int]int // task ID -> completion time
TotalTime int
}
func RoundRobin(tasks []Task, quantum int, context int) Result
Rules
- Time starts at 0.
- Tasks are enqueued in order of arrival time, breaking ties by input order.
- If the ready queue is empty, time jumps to the next task arrival.
- Each task runs for
min(quantum, remaining). - If a task finishes, record its completion time.
- If a task is preempted and no other task is ready, it continues with no context switch cost.
- Otherwise, after each time slice, add
contexttime before the next task runs. - New arrivals during execution or context switch are enqueued immediately when time advances.
Notes
- Ignore tasks with non-positive burst.
contextcan be zero.
Run tests to see results
No issues detected