5
$\begingroup$

I understand the difference between Hoare and Mesa monitors. However I don't understand why priority inversion (when a lower priority process gets done before a higher priority process) is possible in the Hoare type but not possible in the Mesa type. Can someone explain this?

$\endgroup$

1 Answer 1

5
$\begingroup$

Unless you are careful priority inversion is possible in either Hoare type or Mesa type monitors. This is because monitors implement a form of mutual exclusion (only one process can be "in" the monitor at a time), and mutual exclusion and priorities don't mix well. Boosting the priority of the thread in the monitor, mitigates (but does not completely solve) the problem. Priority boosting is typically done either with a priority ceiling, or priority inheritance, or both.

Hoare type condition variables introduce an additional priority inversion problem, though. In Hoare type condition variables a low-priority thread may WAIT on the condition variable (thus giving up the monitor lock), then a high-priority thread could run, make the condition true and SIGNAL the condition variable. In a Hoare type condition variable, the high priority thread immediately loses the monitor lock and gives it to the lower-priority thread.

In a Mesa type condition variable this particular priority inversion won't happen. The low-priority thread WAITs on the condition variable, giving up the monitor lock. Then a high-priority thread runs, makes the condition true and NOTIFYs the condition variable. The high-priority thread does not give up the monitor lock, and keeps running.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.