------------------------------------------------------------------------------- Mohamed G. Gouda CS 356 Summer 2007 Homework 2 Solution ------------------------------------------------------------------------------- 1. (3 Points): process p const v inp m : integer {m>0} var conp : array [0..v-1] of boolean {init. false} cansnd : array [0..v-1] of 0..m par c : 0..v-1 begin timeout ~conp[c] ^ (crqst(c)#ch.p.q + data(c)#ch.p.q + drqst(c)#ch.p.q + crply(c)#ch.q.p + drply(c)#ch.q.p = 0) -> send crqst(c) to q [] rcv crply(c) from q -> conp[c], cansnd[c] := true, m [] conp[c] -> if cansnd[c] > 0 -> send data(c) to q; cansnd[c] := cansnd[c] - 1 [] true -> send drqst(c) to q; cansnd[c] := 0 fi [] rcv drply(c) from q -> conp[c] := false end process q const v var conq : array [0..v-1] of boolean {init. false} par c : 0..v-1 begin rcv crqst(c) from p -> if true -> conq[c] := true; send crply(c) to p [] true -> conq[c] := false; send drply(c) to p fi [] conq[c] -> conq[c] := false [] rcv data(c) from p -> if ~conq[c] -> {discard data message} send drply(c) to p [] conq[c] -> {store data message} skip fi [] rcv drqst(c) from p -> conq[c] := false; send drply(c) to p end ------------------------------------------------------------------------------- 2. (4 Points): Only process q needs to be changed as follows. First, a new integer variable named sp is added to process q. Second, the first action in process q needs to be modified as shown. rcv crqst(x) from p -> if conq ^ sp = x -> y := sq; send crply(x,y) to p [] conq ^ sp != x -> y := sq; send drply(x,y) to p [] ~conq -> conq, sp, y := true, x, sq; send crply(x,y) to q [] ~conq -> conq, sq, y := false, sq+1, sq send drply(x,y) to q fi ------------------------------------------------------------------------------- 3. (3 Points): In order to be able to compare these two protocols, we need to ensure that the numbers of parity bits used in both protocols are equal. Thus for a data block of m*n data bits, we use n parity bits, and for a data block of (m*n)/2 data bits, we use n/2 parity bits. Now there is one-to-one correspondence between the data bits in both protocols and between the parity bits in both protocols. If the corruption of some bits can be detected in one protocol, then corruption of the corresponding bits can be detected in the other protocol. In other words, the two protocols have the overhead and the same effectiveness in corruption detection. However in many cases once corruption is detected the first protocol discards a large block of data bits while the second protocol discards only a small block of data bits. Thus the second protocol is better. -------------------------------------------------------------------------------