Reputation: 386
Two tasks with different priority are waiting on same semaphore, once semaphore gets released task with high priority gets scheduled ? or its random ?, am using SCHED_RR scheduler policy.
Upvotes: 0
Views: 1642
Reputation: 3768
If you are using SCHED_RR
then scheduler runs tasks with highest priority, and runs such tasks in the first place. If there is task with SCHED_RR
and it in state TASK_RUNNING
, it will run.
On uniprocessor system, if exist task with SCHED_RR
and TASK_RUNNING
then only this task will be executing. But on multi-core system, task with lower priority could be scheduled on another processor.
In my opinion, task with higher priority and SCHED_RR
scheduled first, but there is no waranty that this task gets semaphore first, because this processor might do more important work, such as handle interrupts.
Again, this is my only opinion, and I'm fairly new to linux kernel. It would be great to have somebody more experienced to approve it.
Edit:
Scheduler is not important for semaphore. It just wakes up one task regardless of it priority.
So, you can obtain lock first if your task first tries to obtain lock (it's hard and not safe). Or you could manage semaphore queue by yourself.
Upvotes: 1
Reputation: 59446
Generally speaking, I know of no rule which waiting task gets woken up first when a semaphore is released, so it is up to the scheduler's choice. The "priority" of the tasks probably only is relevant for the scheduler in case of the normal scheduling mechanism, not the synchronizing due to semaphores.
Upvotes: 1