Professional Documents
Culture Documents
Burst Time
Priority
P1
P2
P3
P4
P5
5
3
1
2
4
3
5
2
1
4
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|P1|P2|P3|P4|P5|P1|P2|P4|P5|P1|P2|P5|P1|P5|P1| RR
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
(b) Turnaround time:
| FCFS | SJF | Priority | RR
--------+------+-----+----------+-----P1
|
5 | 15 |
12
| 15
P2
|
8 | 6 |
3
| 11
P3
|
9 | 1 |
13
|
3
P4
| 11 | 3 |
15
|
8
P5
| 15 | 10 |
7
| 14
--------+------+-----+----------+-----Average | 9.6 | 7 |
10
| 10.2
(c) Waiting time:
| FCFS | SJF | Priority | RR
--------+------+-----+----------+-----P1
|
0 | 10 |
7
| 10
P2
|
5 | 3 |
0
|
8
P3
|
8 | 0 |
12
|
2
P4
|
9 | 1 |
13
|
6
P5
| 11 | 6 |
3
| 10
--------+------+-----+----------+-----Average | 6.6 | 4 |
7
| 7.2
(d) Shortest Job First (SJF) has the minimal average
waiting time.
/* philosopher i=0,1,2,3,4
think();
if (i % 2 == 1) {
DOWN(fork[i]);
DOWN(fork[(i+1)%5]);
} else {
DOWN(fork[(i+1)%5]);
DOWN(fork[i]);
}
eat();
if (i % 2 == 1) {
UP(fork[(i+1)%5]);
UP(fork[i]);
} else {
UP(fork[i]);
UP(fork[(i+1)%5]);
}}
}
(a) May the above solution lead to deadlock?
(b) What problem could occur in the above solution?
(10 points)
(10 points)
Ans: (a) See the graph.