Question: Is the following code a good solution to the critical section problem? Make sure you talk about all three requirements. The solution is meant for

Is the following code a good solution to the critical section problem? Make sure you talk about all three requirements. The solution is meant for just two processes, numbered 0 and 1 for convenience and passed to the function using the variable i.
/* flag is a shared variable; one for each process */
extern bool flag[2]={ false, false };
process ( const uint i )/* i =0 or i =1*/
{
while (1)
{
flag[i]= true;
while ( flag[1-i]);
critical_section();
flag[i]= false;
remainder_section();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!