Jiemin (Jenny) Zhang

All work

Codexion

A deterministic scheduler for coders competing for shared USB dongles. FIFO and EDF scheduling, deadlock-free resource acquisition, and a monitor that detects burnout within 10 ms.

The problem

Many threads need two shared resources at once, under strict timing rules. Each coder must get both dongles, compile, debug and refactor before a burnout deadline, and the logs must stay in order. The challenge is to avoid deadlock and starvation while staying predictable.

What I built

  • A central scheduler that keeps waiting requests in a priority queue (a binary heap) and picks the next coder by scanning it. It supports FIFO (first come, first served) and EDF (earliest deadline first, where the deadline is the last compile start plus the burnout time).
  • Both dongles are taken inside one scheduler critical section. A coder never holds one dongle while waiting for the other, which removes the hold-and-wait condition.
  • Separate mutexes for the scheduler, the shared state and the time data, to keep the critical sections short. Sleeping always happens outside the locks.
  • A monitor thread that wakes just before the earliest deadline, so a burnout is printed within the 10 ms window. Cooldowns use timed condition waits.
  • Stress test with 200 coders: both policies finish without a burnout in about a second.

Decisions and trade-offs

One scheduler lock
It makes the order of decisions deterministic and easy to reason about. It is also a bottleneck, so throughput is traded for correctness.
Timed waits instead of signalling every event
A coder re-checks at least every 10 ms, so a cooldown that ends silently is still noticed.

Limits and next steps

The availability check scans the waiting requests on every event. It is fast enough for hundreds of coders. For thousands, per-dongle queues would be the next step.