Search code examples
deadlockmutual-exclusion

deadlock and mutual exclusion


Two processes X and Y need to access a critical section. Consider the following synchronization construct used by both the processes.

http://d18khu5s3lkxd9.cloudfront.net//wp-content/uploads/2015/02/Q20.png

In the link given above, varP and varQ are shared variables and both are initialized to false. Which one of the following statements is true?

1.The proposed solution prevents deadlock but fails to guarantee mutual exclusion

2.The proposed solution guarantees mutual exclusion but fails to prevent deadlock

3.The proposed solution guarantees mutual exclusion and prevents deadlock

4.The proposed solution fails to prevent deadlock and fails to guarantee mutual exclusion

According to the question setter 4th answer is the correct answer.

I have figured that it fails to guarantee mutual exclusion but how does it fails to prevent deadlock?


Solution

  • I came up with this after studying the algo carefully.

    Say process Y has used the Critical Section.Therefore,it must have set VarQ variable as false.

    Now if Process X tries to enter Critical Section.It can never enter unless Process Y also tries to enter.Reason being the condition while(varQ == true) will remain false unless Process Y tries to enter Critical Section and in doing so sets VarQ to true which before leaving Critical Section(CS) it had set to false.

    So as we can see if Process Y does not tries to enter CS,Process X is indefinitely blocked and also the Critical Section is lying unused.

    But the question still remains that how is lack of starvation freedom leading to lack of deadlock freedom.In deadlock every process is blocked,but if Process Y indeed tried to enter CS again,Process X could have been successful in its attempt to enter CS.