explain the petersons solution for the critical


Explain the Peterson's solution for the critical section problem?

In Peterson's solution two variables a) flag and b) turn are used as shared variables. If the both shared variables are set after that particular process can get into the critical section. Or else it gives other processes to get into the critical section and consider the segment for a process Pi to get into the critical section.

         do

            {

               flag[i]=true

               turn=j

               while(flag[j]&&turn==j)

               critical section

               flag[i]=false

               remainder section

            }while(1)

 

code segment for a process Pj is as follows:-

do

            {

               flag[j]=true

               turn=i

               while(flag[i]&&turn==i)

               critical section

               flag[j]=false

               remainder section

            }while(1)

 

            When flag[i]=true and turn=j is implemented, let a context switch take place. Therefore the control comes to the process Pj. therefore the statement flag[j]=true is executed. Again a contest switch take place and control is now with Pi. Therefore when the while condition is checked both of the conditions are true. Therefore while condition is true always and it ends up in an infinite loop. Therefore Pi is in an infinite loop and waits till the condition gets false. Therefore Pj executes here first and makes flag[j]=false. Therefore when a context switch occurs, Pi will get into its critical section. Implementation of each process depends on the context switch occurring between the two processes.

Request for Solution File

Ask an Expert for Answer!!
Operating System: explain the petersons solution for the critical
Reference No:- TGS0306887

Expected delivery within 24 Hours