323 views
1 votes
1 votes

Consider the following codes for critical section problem and set of statements 

image:p53.PNG

I) CODE 1 guarantees Mutual Exclusion
II) CODE 2 guarantees Mutual Exclusion
III) CODE 2 leads to Deadlock

Which of the above statements are TRUE

  1.   I and III only
  2.  I and II only
  3.   All I,II and III
  4.   II and III only

1 Answer

1 votes
1 votes

Answer is 4) Statement II : Code 2 gurantees ME and spin lock is possible in it therefore leads to deadlock.


Reasoning :
Counter ex for statement 1)

At the very initial time both have false entries at respective index in shared array ,Now P0 check P1's index which is false and gets preempted and Now P1 hold computation and check P0's index and enters CS and gets Preempted .
After this point both are in CS which leads to Alter the condition of ME.


Condition of Spin lock for statement 3)

P0 asks for CS and make entry true at respective index in shared array and gets preempted
P1 asks for CS and make entry true at respective index in shared array and gets prempted now at this point of time no matter which process gets schedule it gets stuck in while loop and therefore spin lock will result to deadlock.

Related questions

0 votes
0 votes
1 answer
2
0 votes
0 votes
3 answers
3