Describe how a real-time operating system (RTOS) schedules tasks of varying priorities. What is priority inversion, and how do you mitigate it?
Implement simulate_rtos(tasks, ticks, use_inheritance). Each task is a dictionary with name, priority, release, work_before_lock, lock_for, and work_after_lock. Return the task selected at each tick, using "IDLE" when none is runnable, plus the number of inversion ticks. Higher priorities run first; ties use input order. A task blocked on the mutex cannot run. If enabled, priority inheritance temporarily raises the mutex owner's priority to the highest blocked task priority.
def simulate_rtos(tasks, ticks, use_inheritance):