Anonymous user menu

Critical Section question - get_exclusive_acess(){ if(critica



     if(critical_flag == false)


    critical_flag = true;

  critical region();

 critical_flag = false;



does this satisfy mutual exclusion??

according to me if i just preemt  after checking if condition then it voilates mutual exclusion.

is it correct to preempt after if statement????


Dhrupit Dave @dhrupitdave
6 Oct 2014 12:00 pm

Yes. this is correct but the only correction here is to write else condition.

else condition will be 





So, that's it. then your code is perfect.

Tarun Varshney @varshneylive
15 Oct 2014 11:43 am

Preemption is just a temporary stop, the process will come back and continue the remaining execution and preemption can be occur at any point of time.

I think this code does not satisfy the condition of Mutual Exclusion.

Suppose process p1 execute first it reads the critical_flag value as false and 'if statement' become true for process p1. After executing if statement it get preempted nd process p2 arrives. Now p2 reads critical_flag false as true than 'if statement' also true for p2.

In this way both process can enter into critical section.

Or else u can see attached pdf