Process 1 begin time is 0. Process 2 begin time is 2. The code is as follows: Pr
ID: 664096 • Letter: P
Question
Process 1 begin time is 0. Process 2 begin time is 2. The code is as follows:
Process 1: Lock R1, sleep(3), Lock R2, sleep(1), Lock R3, sleep(10), unlock all.
Process 2: sleep(3), Lock R3, sleep(2), Lock R1, sleep(1), unlock all
In this code, Lock Ri means that the process wants resource Ri. If Ri is available, it is given to this process in 0 time. If the resource is not available, appropriate action is taken based on wait-die algorithm in 0 time. Show the execution of the two processes by showing what happens at different times. (If execution proceeds after time 15, you can stop at time 15). Also, remember that process 2 cannot begin until time 2. Assume that sleep of multiple processes is concurrent.
Process 1
Process 2
Time 0
Lock R1; sleep
Not yet running
Time 1
Sleep
Not yet running
2
Sleep
Sleep
3
Sleep
4
5
6
7
8
9
10
11
12
13
14
15
Process 1
Process 2
Time 0
Lock R1; sleep
Not yet running
Time 1
Sleep
Not yet running
2
Sleep
Sleep
3
Sleep
4
5
6
7
8
9
10
11
12
13
14
15
Explanation / Answer
Process 1 begin time is 0. Process 2 begin time is 2. The code is as follows:
Process 1: Lock R1, sleep(3), Lock R2, sleep(1), Lock R3, sleep(10), unlock all.
Process 2: sleep(3), Lock R3, sleep(2), Lock R1, sleep(1), unlock all
Process 1
Process 2
Time 0
Lock R1
Not yet running
Time 1
Sleep
Not yet running
Time 2
Sleep
Sleep
Time 3
Sleep
Sleep
Time 4
Lock R2
Sleep
Time 5
Sleep
Lock R3
Time 6
wait for Lock R3
Sleep
Time 7
wait for Lock R3
Sleep
Time 8
wait for Lock R3
wait for Lock R1
Time 9
wait for Lock R3
Time 10
wait for Lock R3
wait for Lock R1
Time 11
wait for Lock R1
Time 12
wait for Lock R1
Time 13
wait for Lock R1
Time 14
wait for Lock R1
Time 15
wait for Lock R1
Process 1
Process 2
Time 0
Lock R1
Not yet running
Time 1
Sleep
Not yet running
Time 2
Sleep
Sleep
Time 3
Sleep
Sleep
Time 4
Lock R2
Sleep
Time 5
Sleep
Lock R3
Time 6
wait for Lock R3
Sleep
Time 7
wait for Lock R3
Sleep
Time 8
wait for Lock R3
wait for Lock R1
Time 9
wait for Lock R3
wait for Lock R1Time 10
wait for Lock R3
wait for Lock R1
Time 11
wait for Lock R3wait for Lock R1
Time 12
wait for Lock R3wait for Lock R1
Time 13
wait for Lock R3wait for Lock R1
Time 14
wait for Lock R3wait for Lock R1
Time 15
wait for Lock R3wait for Lock R1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.