Professional Documents
Culture Documents
Chapter 5
Lecture 6
Resource Sharing
Presented by:
Ahmed k. Daraj
Introduction
Many shared resources do not allow simultaneous access. When tasks share
resources, scheduling anomalies may occur due to potential priority inversions and
even deadlocks. This chapter discusses how resource sharing and resource
contention affect the execution behavior and schedulability of tasks and how various
resource access control protocols work to reduce the undesirable effect of resource
sharing. We focus on priority-driven and single-processor systems
Resource Sharing
Task may need some resources in addition to a processor in order to make
progress. For example, a computational task may share data with other
computational tasks, and the shared data may be guarded by semaphores each
semaphore is a resource for examples of common resources are:
The task needs units ( 𝜂 ) resource (R) execution time of critical section (c) denote
by [R, 𝜂; c], for one unit only, the simpler notation [R; c] is used.
one unit of R1 for 10 units of time & one unit of R2 for 3 units of time in the critical
section of R1.
• Example 5.1 Critical Sections • The execution time of T2 is 10 units of
time. It has five code segments:
• Figure 5.1 shows the critical
sections of two tasks, namely T1 • [0, 1]: Requires no resources.
and T2. The execution time of T1 is • [1, 4]: Requires R2.
12 units with seven code • [4, 6]: Requires no resources.
segments:
• [6, 8]: Requires R1.
• [0, 2]: Requires no resources.
• [8, 10]: Requires no resources.
• [2, 4]: Requires R1. • The resource requirements of the two
tasks are specified as follows:
• [4, 6]: Requires no resources.
• T1: [R1; 2], [R3; 5[R2; 2]].
• [6, 8]: Requires R3.
• T2: [R2; 3], [R1; 2].
• [8, 10]: Requires R3 and R2.
• [10, 11]: Requires R3.
• [11, 12]: Requires no resources.
Priority Inversion and Deadlocks
Assume that a higher priority task TH and a lower one TL share a resource R.
TH expects to run as soon as it is ready. However, if TL is using the shared resource R
when TH becomes ready to run, TH must wait for TL to finish with it. We say that TH is
pending on the resource.
priority inversion classify into two types as following:
A deadlock occurs when all the following four conditions are met:
❑ Mutual exclusive: One or more resources must be held by a task in an exclusive mode.
❑ Hold and wait: A task holds a resource while waiting for another resource.
❑No preemption: Resources are not preemptable.
❑Circular wait: here is a set of waiting tasks T ={T1, T2, …, TN}, such that T1 is waiting for a
resource held by T2, T2 is waiting for a resource held by T3 and so on, until TN is waiting for a
resource held by T1.
Deadlock
Resource Access Control
Resource sharing can cause serious problems in real-time systems.
We need rules to regulate the access to shared resources as following:
However: there is no protocol that can eliminate priority inversion. A realistic goal
of access control is to keep the blocking time of higher priority tasks under control.
Non-preemptive Critical Section Protocol
P1 3 0 8 8 8 0 0
P2 4 1 2 17 16 14 14
P3 4 3 4 21 18 14 14
P4 5 4 1 22 18 17 17
P5 2 5 6 14 9 3 3
P6 6 6 5 27 21 16 16
P7 1 10 1 15 5 4 4
P1 P5 P7 P2 P3 P4 P6
P1 3 0 8 8 8 0 0
P2 4 1 2 11 10 8 8
P3 4 3 4 21 18 14 14
P4 5 4 1 22 18 17 17
P5 2 5 6 15 10 4 4
P6 6 6 5 27 21 16 16
P7 1 7 1 9 2 1 1
P1 P7 P5 P2 P3 P4 P6