This question evaluates understanding of task scheduling, timing semantics, deterministic ordering, single-thread concurrency control, and data structure choices for managing timed and periodic callbacks.
Design and implement a simple task scheduler for a single CPU, single thread environment.
You need to support scheduling callbacks (tasks) using the following APIs:
scheduleOnce(task, runAtTime)
task
exactly once at the specified absolute time.
scheduleWithDelay(task, delay)
task
exactly once after the specified delay from “now”.
schedulePeriodic(task, initialDelay, period)
task
first after
initialDelay
, then repeatedly every
period
.
Describe the data structures and implement the scheduler logic.