Skip to content

Instantly share code, notes, and snippets.

@yqthu
Created October 24, 2020 13:30
Show Gist options
  • Select an option

  • Save yqthu/5812da7494fd557446218c24dbd0d2ec to your computer and use it in GitHub Desktop.

Select an option

Save yqthu/5812da7494fd557446218c24dbd0d2ec to your computer and use it in GitHub Desktop.
Peterson's algorithm is not starvation-free?
MODULE Process (other_flag, turn)
VAR
pc : {idle, request, critical, release};
flag : boolean;
ASSIGN
init (pc) := idle;
next (pc) :=
case
pc = idle : {idle, request};
pc = request & other_flag & turn : request;
pc = request & (!other_flag | !turn) : {request, critical};
pc = critical : {critical, release};
pc = release : {release, idle};
esac;
init (flag) := FALSE;
next (flag) :=
case
pc = idle & next(pc) = request : TRUE;
pc = release & next(pc) = idle : FALSE;
TRUE: flag;
esac;
MODULE main
VAR
turn : boolean;
alice : Process(bob.flag, turn);
bob: Process(alice.flag, !turn);
ASSIGN
next (turn) :=
case
alice.pc = idle & next(alice.pc) = request : TRUE;
bob.pc = idle & next(bob.pc) = request : FALSE;
TRUE : turn;
esac;
SPEC AG !(alice.pc = critical & bob.pc = critical); -- Mutual exclusion
SPEC AG (alice.pc = request -> EF alice.pc = critical); -- Deadlock-free, No LTL equivalent
SPEC AG (bob.pc = request -> EF bob.pc = critical); -- Deadlock-free
LTLSPEC G F alice.pc = request -> F alice.pc = critical; -- No starvation, Why is this FALSE?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment