605 views

| 605 views

There is no ME, right? Before entering CS,

turn = i would be executed.

That means other process can enter CS as well.

by Junior (617 points)
0
but in CS, turn = i for process i, which means other process will be waiting in the while loop.
0
ME is there.

Isn't the solution incorrect because progress is no there? Once the processes set their flags to true, deadlock will occur.
0

This is clearly peterson's algorithm without explicit condition to check for turn.

 while (flag[1] && turn == 1)
{
// busy wait
}

You see , in given code turn == 1  && flag is not checked in single operation (atomic ).

I'm having hard time believing we'd have ME there.

Consider , after busy wait (do no_op loop) , there was context switch and then P0,P1 might enter CS at same time.

Since Flag is toggled in Remainder , progress is there.

https://en.wikipedia.org/wiki/Peterson%27s_algorithm

This is a correct solution to the critical section problem.

Reason:-

satisfies  mutual exclusion :-value of turn can be either i or j at the same time so any one process can be in cs.

satisfies progress-after execution of each process its flag is set to false (see in the exit section) .as this flag goes to f other waiting process whose flag value is 1(process interested to enter cs) will enter the cs as while loop condition satisfies in this sitiuation.

bounded waiting-after completing its execuion in cs its flag is set to false which allow other process to enter the cs .the same process cant be executed again and again indefinetly if other process is ready and waiting.
by Active (2.3k points)