EASTERN MEDITERRANEAN UNIVERSITY

advertisement
EASTERN MEDITERRANEAN UNIVERSITY
COMPUTER ENGINEERING DEPARTMENT
CMPE-443 – Real-Time Systems Design
Quiz 10.06.2003 (60 minutes, 2 points)
Name, Surname________________________________
Id. #__________________________________
Instructor Alexander Chefranov
Task 1. (0.5 point). Deadlock avoidance (Habermann’s algorithm). Let’s assume that
number of available resources a=10, number of concurrent processes n=4, their
current requests c=(2,1,3,2), their maximal requests b=(10,8,7,4). Decide, whether
granting of c is safe, and if it is so, show safe sequence of processes.
4
r=a-  ci  10  8  2 . S=0;
i 1
B4-c4=4-2=2<=r=2 =>S=S+(P4)=(P4)
B3-c3=7-3=4<=r+c4=4 =>S=S+(P3)=(P4,P3)
B2-c2=8-1=7<= r+c4+c3=2+2+3=7 =>S=S+(P2)=(P4, P3, P2)
B1-c1=10-2=8<= r+c4+c3+c2=2+2+3+1=8 => S=S+(P1)=(P4, P3, P2, P1)
Obtained sequence S contains all 4 processes, hence, required by c resource allocation
is safe, and S is safe sequence.
Task 2. (0.5 point). Assume that current resource state (processes P1..P5, resources
R1..R4) is depicted by the following resource graph:
R2
P2
2
R1
4
P3
P1
R3
2
P4
P5
2
R4
Detect using reduction procedure, whether this current resource situation has a
deadlock. Show sequence of steps of this reduction procedure (sequence of processes
incident to which edges may be eliminated). If deadlocks exist, show processes
involved in deadlocks.
Step 1. We can eliminate edges incident to P5, because it has 1 unit of R3 and
requires 1 unit of R1 which is free now. After elimination 1 unit of R3 will become
free.
Step 2. We can eliminate edges incident to P1, because it has 1 unit of R4, and
requires 1 unit of R1, and this unit is free. After elimination 1 unit of R4 will become
free.
Step 3. We can eliminate edges incident to P3, because it has 2 units of R2, and
requires 1 unit R3( available after Step 1) and 1 unit of R4 (available after Step 2).
After elimination 2 units of R2 will become free.
Step 4. We can eliminate edges incident to P2, because it has 2 units of R1, 1 unit of
R4, and requires 1 unit of R2 (2 units are free after Step 3). After elimination 3 units
of R1 and 2 units of R4 will be free.
Step 5. We can eliminate edges incident to P4, because it has 1 unit of R3 and 1 unit
of R1, and requires 1 unit of R2, being available.
So, all edges are eliminated, it means that there is no deadlock.
Task 3. (1 point). Consider priority preemptive system of 4 processes; patterns of
their work are given in the table below
Process
Priority
Execution
Release time
sequence
A
1
EQVQQE
0
B
2
EQQE
2
C
3
EQVE
3
D
3
EQE
4
Assume that more priority (important) process has larger value of priority. Release
time means time of issuing request for execution of respective task. Execution
sequence corresponds to the sequence of actions which are to be made by the process
in each quantum of processor time: E means just execution without usage of critical
resources, V,Q – means that in respective time slices task must use critical resource V
or Q. Draw time diagram of execution of this system of processes using Original
Ceiling Priority Protocol (OCPP) for resources locking. Calculate response time for
each process. OCPP rules:
1. Each process has a static default priority assigned.
2. Each resource has a static ceiling value defined, this is the maximum priority of
the processes that use it.
3. A process has a dynamic priority which is the maximum of its own static priority
and any it inherits due to it blocking higher-priority processes (when process
blocks higher-priority task it gets temporarily this higher priority).
4. A process can only lock a resource if its dynamic priority is higher than the
ceiling of any currently locked resource (excluding any that it has already locked).
D
P
P
P
E
Q
V
E
E
P
P
P
C
B
A
E
Q
E
P
P
P
P
Q
Q
E
E
Q
P
P
P
P
P
P
P
P
P
P
P
V
Q
Q
E
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
1
2
At moment 0 starts A, at moment 2 it is preempted by B, which is preempted by C at
moment 3. At moment 4 D is released and also is to wait for termination of the same
priority process C. Process C terminates at moment 7, with response time equal to 73=4. At moment 7 D is resumed, and terminates at moment 10 with response time 104=6. At moment 10 resumes B, and terminates at moment 13 with response time 132=11. At moment 13 resumes A, and terminates at moment 17 with response time 170=17. No blocking took place in this scenario.
Download