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
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.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
