----------------------------------------------------------------------------- Mohamed G. Gouda CS 356 Spring 2009 Homework 1 ----------------------------------------------------------------------------- 1. (3 points) Two symmetrical processes p and q exchange data messages such that at each state the number of sent data messages by each process minus the number of received data messages by the same process is at least 0 and at most k, where k is a positive integer. Specify process p in this protocol. What is the maximum number of data messages that can exist in any channel in this protocol? Solution: process p const k var sr : 0..k {init. 0} begin sr < k -> sr:=sr+1; send data to q [] rcv data from q -> if sr=0 -> send data to q [] sr>0 -> sr:=sr-1 fi end Maximum number of data messages that can exist in any channel in this protocol is 2k. ------------------------------------------------------------------------------ 2. (3 points) The protocol in Problem 1 is generalized to involve two process arrays p[i : 0..m-1] and q[j : 0..n-1]. Each process p[i] exchange data messages with each process q[j] such that at each state the number of sent data messages by p[i] to any q[j] minus the number of received data messages by p[i] from q[j] is at least 0 and at most k, where k is a positive integer. Specify process p[i : 0..m-1] in this protocol. Solution: process p[i : 0..m-1] const k, n var sr : array[0..n-1] of 0..k {init. 0} par j : 0..n-1 begin sr[j] < k -> sr[j]:=sr[j]+1; send data to q[j] [] rcv data from q[j] -> if sr[j]=0 -> send data to q[j] [] sr[j]>0 -> sr[j]:=sr[j]-1 end ------------------------------------------------------------------------------- 3. (4 points) Consider a protocol that involves n+1 processes p, q[i : 0..n-1]. Periodically p sends a data message to every q[i], then p waits to receive an ack message from every q[i] before p sends its next data message to each q[i], and the cycle repeats. The sent data or ack messages can be lost (but not corrupted or reordered). When a data message from p to any q[i] is lost, or when an ack message from any q[i] to process p is lost, then process p times out and resends the last data message to process q[i]. (Note that this protocol will cause q[i] to receive at least one, but maybe more than one, copy of each sent data message.) An incomplete specification of process p is as follows: process p const n var ready : array {0..n-1] of boolean {Initially true} wait : 0..n {Initially 0} par i : 0..n-1 begin wait = 0 --> S.0 [] rcv ack from q[i] --> S.1 [] timeout G.i --> send data to q[i] end Specify statements S.0 and S.1 and the timeout guard G.i in process p. Solution: S.0 = do wait wait, ready[wait]:=wait+1, false; send data to q[wait] od S.1 = wait, ready[i]:=wait-1, true G.i = ~ready[i] ^ (#ch.p.q[i]+#ch.q[i].p=0) ------------------------------------------------------------------------------