------------------------------------------------------------------------------- Mohamed G. Gouda CS 356 Spring 2007 Homework 3 Solution ------------------------------------------------------------------------------- 1. (5 points) a) For p[0], both local and global topology information are var up : array[1..n-1] of boolean For p[i:1..n-1], local topology information is var up : bool and, the global toplogy information is var vp: array[1..n-1] of boolean b) process p[0] const n var up: array[1..n-1] of boolean ts : integer, {init. 0} m : 1..n, par g : 1..n-1 begin rcv chk from p[g] -> up[g] := true; send chk to p[g] [] rcv error from p[g] -> skip; [] timeout #ch.p[0].p[g] + #ch.p[g].p[0] = 0 -> up[g] := false; send chk to p[g] [] true -> ts, m := ts+1,1; do m if up[m] -> send st(up,ts) to p[m]; []~up[m] -> skip fi; m := m+1 od end process p[i:1..n-1] var vp,v: array [1..n-1] of boolean, ts,t: integer {initially ts=0} up : boolean begin rcv chk from p[0] -> up := true; send chk to p[0] [] rcv error from [0] -> skip [] timeout #ch.p[i].p[0]+#ch.p[0].p[1]=0 -> up:=false [] rcv st( v,t) from p[0] -> if t<= ts -> skip [] t>ts -> ts,vp := t,v fi end c) The condition that needs to be checked by p[i] is up ^ vp[2] ------------------------------------------------------------------------------- 2. (5 points) process p[i : 0..n-1] inp N : set {g | p[g] is a neighbor of p[i]}, up : array[N] of boolean var h : 0..n-1, dst : array[0..n-1] of boolean, j : 0..n e,f : N par g : N begin true -> h, dst := n-1, any; dst[i] := false; {p[i] cannot be a destination} j := 0; do j < n ^ ~dst[j] -> j := j+1 od; if j = n -> skip [] j < n -> {send a copy of data(h,dst) to each up neighbor} f := NEXT(N,e) do f != e -> if up[f] -> send data(h,dst) to p[f] [] ~up[f] -> skip; fi; f:=NEXT(N,f); od; if up[e] -> send data(h,dst) to p[e] [] ~up[e] -> skip fi fi [] rcv data(h,dst) from p[g] -> if dst[i] -> {store data} dst[i] := false; [] ~dst[i] -> {do not store data} skip fi; h:=h-1 if h=0 -> skip [] h>0 -> f:=NEXT(N,g) do f!=g -> if up[f]-> send data(h,dst) to p[f] [] ~up[f]-> skip fi; f := NEXT(N,f) od; fi; end -------------------------------------------------------------------------------