Книга: Programming with POSIX® Threads
5.5.5.2 Priority inheritance mutexes
5.5.5.2 Priority inheritance mutexes
The other Pthreads mutex protocol is priority inheritance. In the priority inheritance protocol, when a thread locks a mutex the thread's priority is controlled through the mutex (Figure 5.4). When another thread needs to block on that mutex, it looks at the priority of the thread that owns the mutex. If the thread that owns the mutex has a lower priority than the thread attempting to block on the mutex, the priority of the owner is raised to the priority of the blocking thread.
The priority increase ensures that the thread that has the mutex locked cannot be preempted unless the waiting thread would also have been preempted — in a sense, the thread owning the mutex is working on behalf of the higher-priority thread. When the thread unlocks the mutex, the thread's priority is automatically lowered to its normal priority and the highest-priority waiter is awakened. If a second thread of even higher priority blocks on the mutex, the thread that has the mutex blocked will again have its priority increased. The thread will still be returned to its original priority when the mutex is unlocked.
The priority inheritance protocol is more general and powerful than priority ceiling, but also more complicated and expensive. If a library package must make use of priority scheduling, and cannot avoid use of a mutex from threads of differ-ent priority, then priority inheritance is the only currently available solution. If you are writing a main program, and know that none of your mutexes can be locked by threads created within a library, then priority ceiling will accomplish the same result as priority inheritance, and with less overhead.
FIGURE 5.4 Priority inheritance mutex operation
- 16.4.1 Priority Inheritance Protocol
- 16.4.2 Ceiling Priority Protocol
- 16.4.3 Priority Ceiling Protocol
- 5.5.5 Priority-aware mutexes
- 5.5.5.1 Priority ceiling mutexes
- 8.1.4 Beware of priority inversion
- SERVER PRIORITY CLASS
- Using Priority Scheduling and Control
- 3.2.3 Using mutexes for atomicity
- Class Inheritance
- Multiple Inheritance
- Object management, ownership, and inheritance