Preparing your design workspace

Loading the problem and your saved attempt…

Design and Implement a Concurrent Priority Task Scheduler

Model a thread-safe in-process scheduler that orders tasks by priority, cancels pending work safely, and times out running work cooperatively.

Design and implement the core of an in-process task scheduler shared by multiple producer threads. The reported exercise requires priority ordering, timeout cancellation, and thread safety. For this exercise, assume every submitted task has a unique ID, an integer priority, a callback, and a positive execution timeout.

Higher integer priority runs first; equal priorities are FIFO by accepted submission sequence. A fixed worker pool executes callbacks. Callers can submit, cancel a still-pending task, inspect status, and shut the scheduler down gracefully.

A running task that exceeds its timeout receives a cooperative cancellation signal and finishes with TIMED_OUT status; the scheduler does not use unsafe hard thread termination or promise exactly-once external side effects. A callback exception records FAILED and does not terminate a worker.

Graceful shutdown rejects new submissions, drains pending work, and completes only after every admitted callback execution has returned and every accepted task has a terminal status, including a callback that continued briefly after TIMED_OUT. User callbacks never run while scheduler state is locked.

Recurring schedules, persistence across process restart, distributed coordination, and automatic retries are outside scope.

Explain your assumptions, define the object and interface boundaries, walk through cancellation and timeout races, and implement the bounded pending-work core using an ordered queue and synchronization mechanism of your choice.