Anonymous user menu

critical flag problem

Is ans B or C ? can anyone explain?

5Comments
Rajeev Kr @testusr
12 Sep 2015 09:09 am

I think C should be the answer.

Let's say P1 executes the condition checking step (critical_flag == FALSE) which is satisfied for the moment. But, before it executes the next instruction to set the flag to TRUE another process P2 also checks the condition (critical_flag == FALSE). Here P2 will also find it TRUE and will inter into the critical section.
I am not able to find any valid reason for deadlock. 

Parimal Andhalkar @parimal_andhalkar
12 Sep 2015 09:57 am

Ans is D.

Two Cases:

1.Let initially critical_flag = false.  P1 enters..before executing flag = true instruction it gets preempted...therefore P2 can also enters loop.

2.Let initially critical_flag = false.  P1 enters..after executing flag = true instruction it gets preempted...therefore P2 cannot enters loop . P2 unnecessarily wait for P1.. Therefore Deadlock Occurs..

If i am Wrong Please Correct me..

Rajeev Kr @testusr
12 Sep 2015 10:02 am

There is a difference between WAIT and Deadlock. Process is waiting it never means that there is a deadlock. Deadlock is a condition where all the processes are waiting but no one gets the resourse.

Parimal Andhalkar @parimal_andhalkar
12 Sep 2015 06:13 pm

u r correct Rajeev...

Anjan @prab_1
15 Sep 2015 10:12 pm

but how can one tell that above code is deadlock free??