-
Assume the prcesses are called 1, 2, 3, 4, 5, 6, 7, 8, and 9 in this order.
-
The following is a CPU Gantt chart:
111222223333333334444555555566666678888888899
Waiting times are: 0, 3, 8, 17, 21, 28, 34, 35, 43 for a total of 189 and an average of 21.
- The following are CPU Gantt charts for the three CPUs:
1114444666666
22222555555599
333333333788888888
Waiting times are: 0, 0, 0, 3, 5, 7, 9, 10, 12 for a total of 46 and an average of 5.11.
-
- The following is a CPU Gantt chart:
799111444422222666666555555588888888333333333
Waiting times are: 3, 10, 36, 6, 15, 21, 0, 28, 1 for a total of 120 and an average of 13.33
- The following are the CPU Gantt charts for the three CPUs:
744445555555
992222288888888
111666666333333333
Waiting times are: 0, 2, 9, 1, 5, 3, 0, 7, 0 for a total of 27 and an average of 3.
-
- The bound is 1. If P0 is in its entry section and P1 enters it critical section, then when P1 tries to enter its critical section again, flag[0] is 1 and turn is 0 so it cannot enter again. P0 can enter its critical section the next
time it gets the CPU since turn = 0.
- If P1 is in its remainder seciton, then flag[1] = 0 so P0 can enter its critical section.
- Suppose P0 is in its critical section. We know flag[0] = 1.
At the time P0 enetered it critical section, either
flag[1] was 0 or turn was 0.
If flag[1] was 0, it means that P1 was in its remainder section.
If P1 tries to enter its critical section, it must first set turn = 0. Since
flag[0] is 1, P1 is prevented from entering its critical section
until P0 sets flag[0] to 0.
If turn was 0 when P0 entered its critical section, P1 had to have set turn
to 0 after P0 did. This means that P1 had turn = 0 when it entered its while
loop, and so it again cannot enter its critical section until P0 sets flag[0]
to 0.