Professional Documents
Culture Documents
Chapter 9:
Resource Access Protocol
❑ Critical section
A piece of code under mutual exclusion constraints
Tasks entering critical section have to wait until no
other task is holding the resource
NLT, SoICT, 2021
Waiting state caused by resource constraint
scheduling
activation Termination
READY RUN
preemption
Signal Wait
(free resource) (on busy resource)
WAITING
preempts blocked
Higher priority
J1
Lower priority
J2
Problem: the task with higher priority has to wait for the task with lower
priority
NLT, SoICT, 2021
The priority inversion phenomenon
❑ J3 enters critical section first
❑ J1 is blocked, has to wait until J3 signal the resource
❑ J2 preempts J3 ➔ J1 has to wait for J2
J1 blocked
(priority inversion)
Highest-priority
job J1
unbounded execution time
Middle-priority
job J2
Lowest-priority
job J3
General code Critical section
❑ Ji: a job of i
❑ Pi: nominal priority of i
❑ pi Pi: active priority of i ( initially set to Pi)
❑ zi,j: j-th critical section of Ji
❑ di,j: duration of zi,j
❑ Si,j: the semaphore guarding zi,j
❑ Ri,j: the resource used in zi,j
❑ Notation zi,j zi,k means zi,j is entirely contained in zi,k.
NLT, SoICT, 2021
Terminology & assumptions (2)
❑ Assumptions
J1,…,Jn are listed in decreasing order of Pi
Jobs don’t suspend themselves.
The critical sections used by any task are properly nested.
zi,j zi,k or zi,k zi,j or zi,j zi,k=0
Unnecessary blocking
Highest-priority
job J1
Middle-priority
job J2
Blocked by
Lowest-priority PIP
job J3
P1
J3’s active
priority p3 P3
Direct blocking
Highest-priority
job J1
Middle-priority
job J2
Push-through
Lowest-priority blocking
job J3
P2
J3’s active
priority p3 P3
Normal
Critical section
execution
NLT, SoICT, 2021
PIP with nested critical sections
❑ When the blocking job Jk exits the critical section, the
blocked job with the highest priority is awakened.
❑ Jk replaces its active priority pk by nominal priority Pk if no
other jobs are blocked by Jk, or by the highest priority of
the tasks blocked by Jk
Transitive
priority
inheritance