[Return to Bookshelf] [Contents] [Previous Section] [Next Section] [Index] [Help]


3.5.1 Priority Inversion

Priority inversion occurs when interaction among three or more threads blocks the highest-priority thread from executing. For example, a high-priority thread waits for a resource locked by a low-priority thread, and the low-priority thread waits while a middle-priority thread executes. The high-priority thread is made to wait while a thread of lower priority (the middle-priority thread) executes.

To avoid priority inversion, associate a priority (at least as high as the highest priority thread that will use it) with each resource and force any thread using that object to first raise its priority to that associated with the object.

The Default (throughput) scheduling policy prevents priority inversion from causing a complete blockage of the high-priority thread, because the low-priority thread is eventually permitted to execute and release the resource. The FIFO and RR policies, however, do not provide for resumption of the low-priority thread if the middle-priority thread executes indefinitely.