------------------------------------------------------------------------------ Mohamed G. Gouda Midterm 1 CS 356: Computer Networks Spring 2007 Solution ------------------------------------------------------------------------------ 1 (10 points) process p inp n : integer {n.p[0]=5 and n.p[1]=7} var cansend : integer {init. n} begin cansend > 0 -> send data to p[1-i]; cansend := cansend-1 [] rcv data from p[1-i] -> cansend := cansend + 1 end -------------------------------------------------------- 2 (10 points) process p var seq : 0..1 {init. 0} ready : boolean {init. true} begin ready -> send data(seq) to q; ready := false [] rcv ack from q -> ready := true; seq := 1-seq [] timeout(#ch.p.q + #ch.q.p = 0) ^ ~ready -> ready := true end ----- In case of process q below, although the question does not mention how to treat the incoming data, in reality it would either be discarded (duplicate receipt) or accepted (new data), depending on the expected sequence number. process q var exp : 0..1 {init. 0} s : 0..1 begin rcv data(s) from p -> send ack to p if s = exp -> exp := 1-exp; {store data} [] s != exp -> skip {discard data} fi; end