Anonymous user menu

Barrier is a synchronisation

Not understanding this q

linked question 11 & 12   (gate 2006)

Sameer Dubey @sameerz567
15 Nov 2014 12:28 pm

Suppose P1, p2, p3 execute line 2 successfully, and the p3 prempts, p1 and p2 successfully execute and leave the code, but p3 is prempted, now if p1 and p2 come into the code again, then process_arrived=3+2, because only the last process will make process_arrived=0, as you can see in the lines 7-9, and the last process is process is p3, now p1 and p2 will be struck in while loop as (while process_arrived!=3) is true as process_arrived=5, now p3 regains the control and when it tries to execute the while loop it is also struck, therefore all the three processes are struck and there is a deadlock

But you can see deadlock will occur only if two barrier invocations are invoked in succession, i.e p1 and p2 try to enter the barrier second time in succession 

Sameer Dubey @sameerz567
15 Nov 2014 12:29 pm

Using this knowledge you can try to solve 2nd part, its easier, if not solved then re ask