Could you suggest me a quite general way to avoid the priority inversion that may happen in this situation:
Thread1 has priority 1
Thread2 has priority 2
Thread3 has priority 3
Thread1 gets a mutex and enters the critic section
Thread3 stops on the same mutex
Thread2 wakes up so Thread1 is scheduled out for running Thread2
As long as Thread2 runs, Thread3, which has higher priority, is stopped by a lower priority thread for a potentially long time (while Thread1 would have blocked him for the very short time of execution of a critical section)
One way (but i guess pretty time consuming) is to raise up temporarily Thread1 priority to 3 just before getting the mutex (and releasing high priority just after having released the mutex)
This I guess would make me loose much CPU time? Or is it priority change very fast?