Priority Inversion Detector

Hard Python Arbitration Asked at Qualcomm
Solve this problem

Analyse a trace of mutex acquisitions and task priorities to find priority inversions, where a high-priority task waits on a lock held by a lower-priority one.

Constraints

  • Events are (timestamp, task, priority, action, lock) with action in acquire/release/block.
  • Report each inversion as (timestamp, blocked_task, holder_task).
  • Lower priority numbers mean higher priority.
  • A block on a free lock is a trace error and must raise ValueError.
  • Return the list sorted by timestamp.
Starter codePython
1def find_inversions(events):2    # TODO3    return []