5,570 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.7k
views
1 answers
1 votes
Rahul_Rathod_ asked Dec 12, 2018
1,676 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 above
765
views
0 answers
0 votes
Magma asked Nov 19, 2018
765 views
I think that statement iii is false , deadlock can arise in both semaphore as well as monitor (mutex)
1.1k
views
1 answers
0 votes
Shaijal Tripathi asked Nov 7, 2018
1,118 views
Assume Counting Semaphore N=8.On performing 10 down() operations by 10 different processes , first 8 will be successful and last two processes will be ... counting semaphore can let multiple processes access the CS at the same time?
1.1k
views
0 answers
1 votes
srestha asked Oct 4, 2018
1,143 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);