PCP implementation II

Joel Sherrill joel.sherrill at oarcorp.com
Thu May 25 17:24:41 UTC 2006

Sorry for the delay.  I took time off for my birthday.

Martin Molnar wrote:

> Hello,
> could anybody explain why the executing task's priority is raised to 
> ceiling of mutex after the task is inserted into wait queue with 
> priority discipline?  I would expect this to happen when task is taken 
> out the wait queue since it obtained mutex.
It probably is better to do it at that point but see below for more 
comments on why it probably doesn't matter in this

> For clarity, I include a code from cpukit/score/src/coremutexseize.c ( 
> _CORE_mutex_Seize_interrupt_blocking function,  line 57-74):
>  _Thread_queue_Enqueue( &the_mutex->Wait_queue, timeout );
>   if ( _Thread_Executing->Wait.return_code == 
>     /*
>      *  if CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT then nothing to do
>      *  because this task is already the highest priority.
>      */
>     if ( _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
>       if (the_mutex->Attributes.priority_ceiling < 
> executing->current_priority){
>         _Thread_Change_priority(
>           executing,
>           the_mutex->Attributes.priority_ceiling,
>           FALSE
>         );
>       }
>     }
>   }
> Yes, I understand ,if it is done here It does not have to be done 
> later when task obtains mutex.  But tasks are waiting for mutex in a 
> priority order. Therefore the following situation can happen:   At 
> first, task with low priority becomes blocked and its priority is 
> raised to ceiling of mutex. Then, task with higher priority is blocked 
> and is enqueued behind the task with low original priority whose 
> priority is now higher. ( I presume that both task fall into the same 
> priority header.) Finally,  the task with lower original priority 
> obtains the mutex before the task with higher original  priority. I 
> think it is not a desired behaviour.
> Please, let me know if I am not correct.
I'm not following you 100% and not 100% sure this is the best place to 
do the priority adjustment but ...

In the above code, Thread Dispatching is disabled so the thread is 
enqueued at its priority prior to inheriting
the ceiling.  Then dispatching is enabled and this thread is blocked 
until the mutex is released.  The thread being given
the mutex will already be at ceiling priority so will compete for the 
CPU at the inherited priority.

Confusing but the thread queue management uses the pre-inheritance 
priority and when unblocked the thread
will be scheduled at the ceiling priority.


> Thanks.
> Martin Molnar

More information about the users mailing list