使用 VxWorks 反转安全互斥体时为什么需要 SEM_PRIORITY_Q?
在 VxWorks 中,我使用 SEM_INVERSION_SAFE 选项创建互斥体,以防止优先级反转问题。
手册说我必须还使用 SEM_PRIORITY_Q 选项。 这是为什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 VxWroks 中创建互斥信号量时,您有两种选择来处理排队(等待)信号量的多个任务:先进先出或优先级最高的任务。
当您使用 SEM_INVERSION_SAFE 选项时,持有互斥体的任务将被提升到与等待信号量的最高优先级任务相同的优先级。
如果要为信号量使用 FIFO 队列,则内核必须遍历等待互斥体的任务队列以找到具有最高优先级的任务。 此操作不是确定性的,因为遍历队列的时间会随着排队任务数量的变化而变化。
当您使用 SEM_PRIORITY_Q 选项时,内核只需查看队列头部的任务,因为它具有最高优先级。 这是一个恒定时间操作。
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.