Hardware interview practice
Fix event-loss and shared-state monitor bugs
A monitor starts waiting for interrupt only after write_start, but an earlier interrupt must cancel the next write. Concurrent task calls also share static locals. Identify and fix both bugs.
Starting point
Question code
// Events: write_start, interrupt, reset
// Multiple re-entrant monitor calls may be active.Reviewed example
Work through one case
Input
interrupt at cycle 5; write_start at cycle 6Expected output
The cycle-6 write is canceled and the pending interrupt is consumedA lifetime interrupt collector preserves the event before any write-specific task starts.
What to cover
Requirements
- Capture interrupts continuously in persistent state or a queue.
- Atomically consume a pending interrupt when a write begins.
- Use automatic per-call storage or transaction objects.
- Define reset to clear pending interrupts and cancel active work deterministically.
