comp.lang.ada
 help / color / mirror / Atom feed
* Uneasy thoughts about priorities, priority inversion and protected objects
@ 2015-02-27 11:59 Jean François Martinez
  2015-02-27 12:59 ` J-P. Rosen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jean François Martinez @ 2015-02-27 11:59 UTC (permalink / raw)


Both Burns in his "Concurrent and Real Time Programming in Ada" and JP Rosen in his wikibook (in French) about software engineering "implement" (note the scare quotes) protected objects by giving a priority to the protected object that is inherited by a task when it runs in it.  This prioriry must be at least equal to the maximum priority of the tasks that might access the protected object (a task with a higher priority gets an exception). ¨Purpose is to avoid priority inversion when a task with high priority cannot enter a protected object because a task with low priority is in it and this cannot get the processor (and out of the protected object) because a task with medium priority is running.  The merit of this model is that it makes protected objects very easy to implement (on monoprocessors): no need of semaphores: once a task is in a protected object no other task can enter it because it cannot get the processor.

Burns tells this model is recommended/mandated (don't remember) by the ARM.

Problem is: there are still priority inversions.  Let's consider the following scenario.  Task High is sleeping, Task Medium is waiting for I/O, Task Low is in protected Object.  Now I/O completes so Task Medium should get the processor but it doesn't because Low is in protected object with High's priority or more.  But nobody is waiting for the protected object so there is no hurry in getting Low out of it and no reason to delay Medium jsut because Low is in Protected Object.  Agreed you are not supposed to spend much time in Protected Objects so you can consider it is no big deal but it is not satisfactory.  It also raises the question of if such a model really allows concurrent readers in practice when in monoprocessors.

It seems to me a task on a protected object should have its priority raised only when a task with a higher priority queues behind it.  In that case its priority should become 
Max(Own_Priority, Max(Priority_of_Processes_in_the_Queue)).  With this model:
Low is in Protected_Object running at Low priority, Medium's I/O ends so Medium gets the processor, High awakes, grabs the processor from Medium and queues on the protected object, Low gets its priority raised to High, resumes running, leaves the protected object and returns to its  normal priority (Low), High gets the processor, enters the protected object and keeps running until it decides to release it.  Medium gets the processor.  
Zero priority inversions.   Also we can have multiple readers, even in monoprocessors.  At least when second reader has ahigher priority than first one.  

Since I don't think for a second none of the smart people who designed Ada and none of the smart people who have read either the ARM, Burns'book or Rosen's wikibook haven't ever had a so obvious idea why is that we still are in the model I described on the first paragraph?  Because it is simpler to implement?  Because it is no big deal?  (You are supposed to leave the protected object _fast_).  Or is it because I missed someting? 

---

Jean-François Martinez


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-03-02 11:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-27 11:59 Uneasy thoughts about priorities, priority inversion and protected objects Jean François Martinez
2015-02-27 12:59 ` J-P. Rosen
2015-02-27 13:21 ` Dmitry A. Kazakov
2015-03-02 11:29 ` Jean François Martinez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox