operating-systemcritical-sectionpriority-inversion

Interruption of process in critical section


In Priority based scheduling, I came across the problem of Priority inversion which is a higher priority process is forced to wait for the lower priority task. One possible scenario is, consider three process L,M,H with order of priority L < M < H .

L is running in CS ; H also needs to run in CS ; H waits for L to come out of CS ; M interrupts L and starts running ; M runs till completion and relinquishes control ; L resumes and starts running till the end of CS ; H enters CS and starts running.

Here, my question is, regarding the statement M interrupts L and starts running i.e., can a process executing in Critical section be interrupted or pre-empted.


Solution

  • The answer is simple and yes. If someother process with a higher priority in a preemptive system doesn't need to run in critical section, i.e. doesn't need to aquire a lock which is held by a lower priority process, then it can preempt the lower priority process regardless of what it is executing.

    Even if M needs the CS, it will preempt L, run, get blocked and switched out for L to continue execution.