I am trying to understand the algorithms by Peterson and Dekker which are very similar and display a lot of symmetries.
I tried to formulate the algorithms in informal language like follows:
Peterson's: "I want to enter." flag[0]=true;
"You can enter next." turn=1;
"If you want to enter and while(flag[1]==true&&turn==1){
it's your turn I'll wait." }
Else: Enter CS! // CS
"I don't want to enter any more." flag[0]=false;
Dekker's: "I want to enter." flag[0]=true;
"If you want to enter while(flag[1]==true){
and if it's your turn if(turn!=0){
I don't want to enter any more." flag[0]=false;
"If it's your turn while(turn!=0){
I'll wait." }
"I want to enter." flag[0]=true;
}
}
Enter CS! // CS
"You can enter next." turn=1;
"I don't want to enter any more." flag[0]=false;
The difference seems to be the point where "You can enter next."
occurs and the fact that "if it's your turn I don't want to enter any more."
occurs in Dekker's.
In Peterson's algorithm, the two processes seem to be dominant. A process seems to force his way in into the critical section unless it's the other one's turn.
Conversely, in Dekker's algorithm, the two processes seem to be submissive and polite. If both processes want to enter the critical section, and it's the other one's turn, the process decides to no longer want to enter. (Is this needed for starvation-freedom? Why?)
How exactly do these algorithms differ? I imagine that when both processes try to enter the critical section, in Peterson's, the process says "I enter", while in Dekker's the process says "You may enter". Can someone clear up the way the processes behave in each algorithm? Is my way of putting it in informal terms correct?