================== Priority Inversion ================== Priority Inversion * Can occur in multi-tasking systems * It is a condition where a lower priority task effectively blocks a higher priority task from accomplishing its job Priority Inversion example ========================== .. code-block:: c // Data acquisition thread ImportantTask() { SSetPriority(HIGHEST) While(TRUE) { //... Sleep(1 second) AcquireSemaphore(pDatabaseSem) // ... work on database ReleaseSemaphore(pDatabaseSem) } } // Database statistics thread MenialTask() { SetPriority(LOWEST) While(TRUE) { //... Sleep(5 minutes) AcquireSemaphore(pDatabaseSem) //... check database statistics ReleaseSemaphore(pDatabaseSem) } } * Can be difficult to detect * Solutions - Don't share semaphores in this fashion by design * Priority Inheritance - supplied by some OSs * OS bumps low-priority tasks priority to that of high priority task for duration of inversion. (Sometimes only one-level deep, can be costly and non-deterministic)