Hardware Reference
In-Depth Information
normal execution
critical section
direct blocking
push-through blocking
τ
1
τ
2
τ
3
t
0
t
1
t
2
t
3
t
4
t
5
t
6
t
7
p
3
P
1
P
2
P
3
Figure 7.8
Example of Priority Inheritance Protocol.
From this example, we notice that a high-priority task can experience two kinds of
blocking:
Direct blocking
. It occurs when a higher-priority task tries to acquire a resource
already held by a lower-priority task. Direct blocking is necessary to ensure the
consistency of the shared resources.
Push-through blocking
. It occurs when a medium-priority task is blocked by a
low-priority task that has inherited a higher priority from a task it directly blocks.
Push-through blocking is necessary to avoid unbounded priority inversion.
Note that in most situations when a task exits a critical section, it resumes the priority
it had when it entered. This, however, is not always true. Consider the example
illustrated in Figure 7.9. Here, task
τ
1
uses a resource
R
a
guarded by a semaphore
S
a
, task
τ
2
uses a resource
R
b
guarded by a semaphore
S
b
, and task
τ
3
uses both
resources in a nested fashion (
S
a
is locked first). At time
t
1
,
τ
2
preempts
τ
3
within its
nested critical section; hence, at time
t
2
, when
τ
2
attempts to lock
S
b
,
τ
3
inherits its
priority,
P
2
. Similarly, at time
t
3
,
τ
1
preempts
τ
3
within the same critical section, and
at time
t
4
, when
τ
1
attempts to lock
S
a
,
τ
3
inherits the priority
P
1
. At time
t
5
, when
τ
3
unlocks semaphore
S
b
, task
τ
2
is awakened but
τ
1
is still blocked; hence,
τ
3
continues
its execution at the priority of
τ
1
. At time
t
6
,
τ
3
unlocks
S
a
and, since no other tasks
are blocked,
τ
3
resumes its original priority
P
3
.
Search WWH ::
Custom Search