In Interview Camp's Live Session today, we discussed a common design problem - design a job scheduler. A job scheduler has a simple interface - you're given a job and a start time for the job. Your scheduler should run the job at the prescribed start time.
The typical design for this question contains a Min Heap of tasks. An executor thread picks up the task that has the Min start_time, waits for the start time, and then executes the task.
Pop the Heap, thread.wait(), execute
We do this in a loop.
During the session, we wrote code for this problem, attached below in the document.
We also discussed race conditions - how to find and resolve them.
We have attached notes from the discussion below. To access these live, please join our trial at Interview Camp!