views:

233

answers:

1

In VxWorks, I am creating a mutex with the SEM_INVERSION_SAFE option, to protect against the priority inversion problem.
The manual says that I must also use the SEM_PRIORITY_Q option. Why is that?

+1  A: 

When creating a mutex semaphore in VxWroks, you have two options to deal with multiple tasks queued (waiting) for the semaphore: FIFO or Highest priority task first.

When you use the SEM_INVERSION_SAFE option, the task holding the mutex will be bumped up to the same priority as the highest priority task waiting for the semaphore.

If you were to use a FIFO queue for the semaphore, the kernel would have to traverse the queue of tasks waiting for the mutex to find the one with the highest priority. This operation is not deterministic, as the time to traverse the queue changes as the number of tasks queued changes.

When you use a SEM_PRIORITY_Q option, the kernel simply has to look at the task at the head of the queue, as it is the highest priority. This is a constant time operation.

Benoit