edited by
353 views
1 votes
1 votes
Initial values of S1 ansd S2 are random assigned

Method by P1

do

{
flag[i] = true;

S1 =  S2;

while( flag[j]=true and S1 == S2);

critical section

flag[i]=false;

remainder section

}while(1);

Method used by P2

do

{

flag[j]=true;

S1=S2+1;

while(flag[i]=true and S1!=S2);

criticals ection

flag[j]=false;

remainder section

}

while(1);

Does this gurantee mutual exclusion?
edited by

1 Answer

0 votes
0 votes
It will guarantee mutual exclusion and infact its the peterson solution for two processes i guess the confusion you are holding is that when both of them want to enter critical section .
In that scenario anyone will enter and second one will block why?
Because they both turn the array flag =true at their respective index but execution of s1 and s2 part i.e next line would be result of any one of them either both the mutex will be equal or they will not ./

Which result ultimately blocking one of them as while will be true.

Related questions

0 votes
0 votes
2 answers
1
shivajikobardan asked Jul 22, 2023
726 views
Sorry if this is a stupid question. But it really intrigued me. Same resources at different algorithms are telling different ways to test these stuffs.Here's an algorith...
0 votes
0 votes
1 answer
3