Anonymous user menu

Semaphores Logic Please help me to understand

Please any one can help to understand and solving procedure for Semaphores problems. Please see the attached problem. Post the solution with explanation

2Comments
sambasivarao @ssrao
21 Oct 2016 01:57 pm

Ans B

Sumit Verma @sumitverma
21 Oct 2016 02:42 pm

Semaphores are the variables on which read,modify and update happens atomically in kernal mode.
Two operations are defined on binary semaphore variables m and n .
wait(m):- if initially m is 1 then after wait(m),m will be 0 .Otherwise it will wait.
signal(m):- if initially m is 0 then after signal(m),m will be 1.

Now in this question suppose if P1 executes wait(m) and got preempted and then P2 executes wait(n) . Now both the semaphore variable m and n are 0.
Now while executing wait(n), P1 will wait untill n will become 1. Also while executing wait(m), P2 will wait untill m will become 1 .
Hence both the process will be in infinite waiting so this is the condition of Deadlock.
Also if order of execution of instruction defines the result then it is called race condition. Here if P1 executes wait(n) first or if P2 executes wait(m) first , then in both of the cases result will be differnt .
So race condition is also present.