# Priority inherance issue

xi yang hiyangxi at gmail.com
Wed May 20 10:32:24 UTC 2009

```Priority A >(higher)B>C>D
T1: D obtains S2. Then S2.before = D
T2: D obtains S1. Then S1.before =  D
T3: C tries to obtains S1 and blocks. D's priority is improved to C,
S1.before = D, S1.after=C
T4: B tries to obtain S2 and blocks. D's priority is improved to B,
S2.before = C, S2.after=B
T5: A tries to obtain S1 and blocks, D's priority is improved to A,
S1.before=B, S1.after = A
T6: D releases S1. D's priority is decreased to B
T7: A get and release S1
T8: D releases S2. D's priority is decreased to C. But D's init priority is D.

Is it the problem you have said?

But, after D releases S2, kernel knows that D doest not hold any
inherent mutex. So just set the priority of D back to the init
priority.

I know, my method has problems like this:

Priority A >(higher)B>C>D
T0: D obtains S3, Then S3.before = D
T1: D obtains S2. Then S2.before = D
T2: D obtains S1. Then S1.before =  D
T3: C tries to obtains S1 and blocks. D's priority is improved to C,
S1.before = D, S1.after=C
T4: B tries to obtain S2 and blocks. D's priority is improved to B,
S2.before = C, S2.after=B
T5: A tries to obtain S1 and blocks, D's priority is improved to A,
S1.before=B, S1.after = A
T6: D releases S1. D's priority is decreased to B
T7: A get and release S1
T8: D releases S2. D's priority is decreased to C.

T9: Now, D have got S3 and there is no higher priority thread waiting
on S3. But D's priority is C. Theoretically, this is a problem (D's
priority should be D). But I think the priority of D is higher (May
not equal) than any threads who wait for mutex held by D. Then, we can
avoid priority invertion.

So, could we say that after release a inherent mutex, the priority of
holder is not less than threads who wait for mutex held by the holder
?

This method is not perfect. But the cost of it is small.