/\ toSend = 10
/\ pc = [S |-> "l_send", R |-> "Done"]
CONSTANT PckCount
ASSUME PckCount \in Nat \ {0}
--fair algorithm simple
{
variables msgC = <<>>; ackC = <<>>;
macro Send(m, chan) {
chan := Append(chan, m)
}
macro Rcv(v, chan) {
await chan /= <<>>;
v := Head(chan);
chan := Tail(chan);
}
process (Sender = "S")
variables toSend = 0; ack = 0;
{
l_send:
while (toSend < PckCount) {
either {
Send(toSend, msgC);
}
or {
Rcv(ack, ackC);
l_depart:
\* if ack received, send next two packets
if (ack = (toSend + 1)) {
toSend := ack;
}
}
}
}
process (Receiver = "R")
variables next = 0; msg = 0;
{
l_rcv:
while (next < PckCount) {
either {
Send(next, ackC);
}
or {
Rcv(msg, msgC);
l_accept:
if (msg = next) {
next := next + 1 ;
}
}
};
l_finish_rcv:
Send(next, ackC);
}
}