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 algorithm and how I'd test for its 3 things.
Process Larry:
do{
while(turn!="Larry");
critical section
turn="Jim";
remainder section
}while(TRUE);
}while(1);
Mutual Exclusion:
No two cooperating processes can enter into their critical section at the same time. For example, if a process P1 is executing in its critical section, no other cooperating process can enter in the critical section until P1 finishes with it.
1) Initially turn="Larry".
2) Larry and Jim both want to enter critical section.
3) But only Larry succeeds because turn="Larry".
So, mutual exclusion is achieved.
Progress:
1) Larry Enters his critical section.
2) Larry Finished his critical section.
3) Larry sets the turn to Jim.
4) Jim Enters the critical section/
5) Jim Finished his critical section.
6) Jim sets the turn to Larry.
7) Jim quickly finishes his remainder section whereas Larry is stuck indefinitely in his remainder section.
8) Jim can't access the critical section again till Larry doesn't access Critical Section and set turn to Jim.
Thus it fails to achieve Progress.
Bounded Waiting:
1) Let turn="Larry".
2) Larry executes his critical section.
3) Larry wants to execute his critical section again.
4) But it immediately sets turn="Jim".
5) Larry executes his remainder section.
6) Even if Jim doesn't want access to critical section, Larry won't be able to access the critical section.
Now,I want to test these 3 conditions for another algorithm, which is given below.
Initially both the flags are false; flag[0]=flag[1]=F.
P_0
while(true)
{
flag[0]=T;
while(flag[1]==T);//wait if P_1's turn
critical section
flag[0]=F
}
P_1
while(true)
{
flag[1]=T;
while(flag[0]==T);//wait if P_0's turn
critical section
flag[1]=F
}
How do I follow a specific approach to test it? Or does it not exist? I want a mental model to think about testing these 3 things in each algorithm.