Search code examples
javamultithreadingconcurrencyhappens-beforepriority-inversion

Does happen-before relationship impact priority inversion?


I am wondering does happen-before relationship such as volatile variable or finally block to release a lock have something to do priority inversion? I understand that these impose a happen-before relationship that the compiler can't reorder the instruction. Does it also impact priority inversion at all, or are they separate concepts? Can someone give me an example to understand this better?


Solution

  • Separate concepts. "Priority inversion" is the idea that if some high-priority thread P is blocked, waiting for a lower-priority thread L to do something, then it would be advantageous for the OS to temporarily boost the priority of L to be at least as high as the priority of P.

    "Happens Before" is a guarantee made in the Java Language Specification that helps us to reason about if and when memory updates made by one thread become visible to some other thread.