Our algorithm is correct, but it is not fair. It does not guarantee
that a process that wants to enter its critical-section will always do
so eventually. Demonstrate this by trying to show a bounded trace of
length 10, such that the second process is ready but never transitions
to critical. We have:
>>> notFair 10
Fairness is violated at bound: 10
P1: [Idle,Idle,Ready,Critical,Idle,Ready,Critical,Critical,Idle,Ready]
P2: [Idle,Ready,Ready,Ready,Ready,Ready,Ready,Ready,Ready,Ready]
Ts: [1,1,1,1,1,1,1,1,1,1]
As expected, P2 gets ready but never goes critical since the arbiter
keeps picking P1 unfairly. (You might get a different trace depending
on what z3 happens to produce!)
Exercise for the reader: Change the
validTurns function so that
it alternates the turns from the previous value if neither process is
in critical. Show that this makes the
notFair function below no
longer exhibits the issue. Is this sufficient? Concurrent programming
is tricky!