Consider the following code for processes P1, P2 and P3, which share three semap
ID: 3681606 • Letter: C
Question
Consider the following code for processes P1, P2 and P3, which share three semaphores x, y and z each with 1 as initial value and three variables a, b and c.
Code for P0: (1.1) wait(x); (1.2) a = a + 1; (1.3) wait(y); (1.4) b = b - a; (1.5) wait(z); (1.6) c = a + 2*b -c; (1.7) signal(z); (1.8) signal(y); (1.9) signal(x) Code for P1: (2.1) wait(y); (2.2) b = b*2; (2.3) wait(z); (2.4) c = c - b; (2.5) signal(y); (2.6) wait(x); (2.7) a = a + c; (2.8) signal(x); (2.9) signal(z) Code for P2: (2.1) wait(y); (2.2) b = b*2; (2.3) wait(z); (2.4) c = c - b; (2.5) signal(z); (2.6) signal(y); (2.7) wait(x); (2.8) a = a / 10; (2.9) signal(x) Question: A. If P0 and P1 run concurrently on a computer with only a single CPU, is it possible for these two processes to get into a deadlock? If so, show one execution sequence of the code that results in the deadlock, and show how to revise P1 only (P0 is not changed) to prevent deadlock. B. If P0 and P2 run concurrently on a computer with only a single CPU, is it possible for these two processes to get into a deadlock? If so, show one execution sequence of the code that results in the deadlock, and show how to revise P2 only (P0 is not changed) to prevent deadlock.
Explanation / Answer
Please find the answers below:
A)
Yes, if P0 and P1 run concurrently, then there is chance of getting into a deadlock. P0 at (1.3) it will wait for y, untill the P1 signals y at (2.5), by this time P1 will acquire z. After signalling y, p1 will try to get z at (1.5), but this z is already acquired by P1 at (2.3) and also the P1 is waiting for x at (2.6) thus both the processes will run into a deadlock
B)
No, if P0 and P2 run concurrently, then there is no chance of getting into a deadlock.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.