Priority Inversion

One of the joys of working with RealTime systems. It happens when using LockBasedSynchronization.

PriorityInversion is a phenomenon commonly associated with shared resources and their management.

High priority threads end up waiting for low priority threads to release resources because all get the same locks on the same resources. Since high priority threads leave few CPU resources to low priority threads, it takes time for low priority threads to release the resources that high priority threads are waiting for.

Especially harmful is when a high priority thread blocks on a resource held by a low-priority thread, and a medium priority thread gets the CPU and doesn't block. In such a situation, the high-priority thread may be starved.

A common solution to the problem (implemented by many RealTime OperatingSystems) is PriorityInheritance, but that technique has its own flaws.


The description below is for ProcessStarvation or better named ThreadStarvation? (when a thread can't continue because shared resources are never available for it, since other threads have more priority):

Thread A has a higher priority than Thread B. Thread B requests Resource C and blocks on that request, either because some medium priority Thread D delays it, or because some other condition forces it to wait. Thread A also needs Resource C and tries to get control of it. Because Thread B is continually interrupted by Thread A, it never finishes with Resource C, which leads to the higher priority Thread A failing because the lower priority Thread B *can't* release the resource because it never gets enough time to complete its task.

(Although we don't make gadgets that crawl around on Mars, we do make gadgets that have to interact directly with people. We have found that there's just nothing like actual people to discover latent inversions in production environments.)


Related: MarsPathfinder


Links:


CategoryConcurrency


EditText of this page (last edited January 6, 2008) or FindPage with title or text search