Question: The below pseudo code for 3 separate processes with 3 different semaphores results in a deadlock (i.e. it is unsafe). Find the condition allowing the
The below pseudo code for 3 separate processes with 3 different semaphores results in a deadlock (i.e. it is unsafe). Find the condition allowing the deadlock and draw the resource allocation graph (RAG) representing the systems state when it happens.
Semaphores: x = 1, y = 2, z = 3;

Process 1 while(1) { Sem_wait(x); Sem_wait(y); Sem_wait(z); Do_operation10); Sem_post(z); Sem_post(y); Sem_post(x); } Process 2 while(1) { Sem_wait(y); Sem_wait(z); Do_operation 20); Sem_wait(x); Sem_post(z); Do_operation3(); Sem_post(y); Sem_post(x); Process 3 while(1) { Sem_wait(y); Sem_wait(x); Sem_wait(z); Do_operation 40); Sem_post(z); Sem_post(x); Sem_post(y); } Process 1 while(1) { Sem_wait(x); Sem_wait(y); Sem_wait(z); Do_operation10); Sem_post(z); Sem_post(y); Sem_post(x); } Process 2 while(1) { Sem_wait(y); Sem_wait(z); Do_operation 20); Sem_wait(x); Sem_post(z); Do_operation3(); Sem_post(y); Sem_post(x); Process 3 while(1) { Sem_wait(y); Sem_wait(x); Sem_wait(z); Do_operation 40); Sem_post(z); Sem_post(x); Sem_post(y); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
