------------------------------------------------------------------------------- Mohamed G. Gouda CS 356 Summer 2008 Midterm 1 ------------------------------------------------------------------------------- 75 minutes Open Book ------------------------------------------------------------------------------- 1. (10 points) Consider a protocol that consists of two symmetric processes p and q. The execution of this protocol proceeds in an infinite sequence of "rounds". In each round, each process generates a random bit b and sends it in a data(b) message to the other process in the protocol. After generating one bit and receiving another bit, each process sums up the two bits and stores the resulting bit in the next available element of its array "round". (Note that the bit sum of 1+1 is 0.) An incomplete specification of process p is as follows. process p var round : array [integer] of 0..1, x : integer, {index of round; init. 0} b,z : 0..1, {init. 0} gen : boolean {init. false} begin ~gen --> b := random; z := z +2 b; send data(b) to q; gen := true [] rcv data(b) from q --> end Specify statements S. ------------------------------------------------------------------------------- 2. (10 points) In a protocol involving two processes p and q, assume that the messages sent from p to q can be corrupted, lost, or reordered but the messages sent by q remain in the channel from q to p unchanged until they are received by p. An incomplete specification of p and q is as follows. process p inp data : array [integer] of integer var x : integer, {index of data, init.0} ready : boolean {init. true} begin ... end process q var rcvd : array [integer] of integer, y : integer, {index of rcvd, init.0} z : integer begin rcv msg(z) from p --> [] rcv error from p --> skip end Complete the specifications of processes p and q such that p sends the elements of its input array data one by one in messages of the form msg(data[x]) to process q which then stores the received elements in its variable array rcvd. Note that eventually the two arrays data and rcvd become identical. -------------------------------------------------------------------------------