โš™๏ธ Engineering

Everyone Wants the Sensors

Stardate 55155.5 ยท UES Magnanimous

Briefing

Welcome to Engineering. Six science teams have queued for the long-range array, and each request runs at the same time as the others. Two teams have received identical timeslots. Lt. Skree reports this is "arithmetically impossible, and yet". Commander Raghunathan has stopped sighing, which everybody agrees is the bad sign.

The scheduler looks at the first free slot, then goes off to talk to the array, then takes the slot. Between looking and taking, it lets go, and another request looks at the same slot. That gap is the whole bug. In Python the gap is an await. In Rust it is the moment between two separate locks, and the fix is to hold one lock across the choice and the take. Ensign Tannenbaum wrote the gap. He says it "seemed polite".

Mission objectives

ARCHIE checks all five every time you run diagnostics.

  • โ€ขEvery team receives a slot
  • โ€ขNo slot is issued twice
  • โ€ขWhen teams equal slots, every slot is used and none is left free
  • โ€ขA seventh team, with six slots, gets None instead of a crash
  • โ€ขThe requests can still run concurrently
Ask Commander Raghunathan for a hint

Python: take the slot before the await, in one step (pop), so nothing can slip in between. Rust: lock once, choose and remove inside that single lock, then let go.