5,429 views
2 votes
2 votes

Let m[0]....m[4] be mutexes (binary semaphores) and P[0].......P[4] be processes.  Suppose each process P[i] executes the following:

wait (m[i]; wait (m(i+1) mode 3]);
     ........... 
     release (m[i]); release (m(i+1) mod 3]);

Will it cause Starvation and deadlock?

If the code change like this

wait (m[i]; wait (m(i+1) mode 5]);
     ........... 
     release (m[i]); release (m(i+1) mod 5]);

Is there any change in answer in this question?

1 Answer

Best answer
3 votes
3 votes

M0,M1,M2,M3,M4 ----- 5 binary semaphores

P0,P1,P2,P3,P4 ----- 5 processes

 

1)

  P0 P1 P2 P3 P4
wait(m[i]) wait(m[0]) wait(m[1]) wait(m[2]) wait(m[3]) wait(m[4])
wait(m[i+1] mod 3) wait(m[1]) wait(m[2]) wait(m[0]) wait(m[1]) wait(m[2])

 

if every process executes wait(m[i]) then it will lead to dead lock.

 

2)

  P0 P1 P2 P3 P4
wait(m[i]) wait(m[0]) wait(m[1]) wait(m[2]) wait(m[3]) wait(m[4])
wait(m[i+1] mod 5) wait(m[1]) wait(m[2]) wait(m[3]) wait(m[4]) wait(m[0])

 

if every process executes wait(m[i]) then it will also lead to dead lock.

 


 

even if you change the sentences as  wait(m[i+1] mod 3); wait(m[i]); instead of wait(m[i]); wait(m[i+1] mod 3); 

 

1)

  P0 P1 P2 P3 P4
wait(m[i+1] mod 3) wait(m[1]) wait(m[2]) wait(m[0]) wait(m[1]) wait(m[2])
wait(m[i]) wait(m[0]) wait(m[1]) wait(m[2]) wait(m[3]) wait(m[4])

 

if every process executes wait(m[i+1] mod 3) then it will lead to dead lock.

 

2)

  P0 P1 P2 P3 P4
wait(m[i+1] mod 5) wait(m[1]) wait(m[2]) wait(m[3]) wait(m[4]) wait(m[0])
wait(m[i]) wait(m[0]) wait(m[1]) wait(m[2]) wait(m[3]) wait(m[4])

 

if every process executes wait(m[i+1] mod 5) then it will lead to dead lock.

edited by

Related questions

1 votes
1 votes
1 answer
1
Rahul_Rathod_ asked Dec 12, 2018
1,503 views
a) s1-wait(p) , s2-wait(q) , s3-wait(q) , s4-wait(p)b) s1-wait(p) , s2-wait(q) , s3-wait(p) , s4-wait(q)c) s1-wait(q) , s2-wait(p) , s3-wait(p) , s4-wait(q)d) none of...
0 votes
0 votes
0 answers
2
1 votes
1 votes
0 answers
4
srestha asked Oct 4, 2018
1,062 views
Will it causing deadlock? How do we fixed it?P1: P2: Wait(S); Wait(Q); Wait(Q); Wait(S); ........ ............. Signal(S); Signal(Q); Signal(Q); Signal(S);