Alex
Alex

Reputation: 13116

Does Linux use some of the solutions of priority inversion?

As known, priority inversion problem - when a thread with higher priority waits for a thread with lower-priority: https://en.wikipedia.org/wiki/Priority_inversion

It happen when we have 3 threads: L (low), M (medium), H (high-priority). L and H use the same mutex, but L acquire it early than H, and H blocked and goes to sleep. And then M occupies CPU-core because has higher priority than L, and L goes to sleep, but mutex still acquired. L & H are sleeping, but M is working.

There are some solutions of priority inversion:

Does Linux use some of the solutions of priority inversion, and which of its?

Upvotes: 2

Views: 4510

Answers (1)

Alex
Alex

Reputation: 13116

Linux uses Priority inheritance.

Priority inversion can be solved by using function int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol);

Where protocol is:

When a thread owns one or more mutexes initialized with the PTHREAD_PRIO_PROTECT protocol, it shall execute at the higher of its priority or the highest of the priority ceilings of all the mutexes owned by this thread and initialized with this attribute, regardless of whether other threads are blocked on any of these mutexes or not.

Upvotes: 4

Related Questions