In the following function:
int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr,
int protocol);
You can define the protocol for a mutex attribute. Following protocols are available:
I know when PTHREAD_PRIO_INHERIT is selected, the task which holds the lock get the highest priority of all tasks(process(if shared between processes) or thread) which you are blocking. This prevents against priority inversion. But PTHREAD_PRIO_PROTECT seems to do the same. So my question is, what is the difference between both protocols ?
See the specification in POSIX.
In short, the differences ares:
With PTHREAD_PRIO_INHERIT
, the thread holding the lock inherits the priority of the highest-priority thread currently contending for the lock (no elevated priority if no other threads are blocked trying to get the lock).
With PTHREAD_PRIO_PROTECT
, the thread holding the lock always runs with elevated priority determined not by other threads contending for the lock, but by a property of the lock (its priority ceiling) configured on a per-lock basis.
You may also want to see the Wikipedia article on the topic to understand the motivations by which one or the other may be chosen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With