------------------------------------------------------------------------------- Mohamed G. Gouda CS 356 Spring 2008 Homework 1 ------------------------------------------------------------------------------- 1. (Huffman Coding: 5 points) A process p has the following input array: inp data : array[integer]of 0..3 Process p needs to send each element of array data to process q so that q can store the received elements in the following variable array: var rcvd : array[integer]of 0..3 Process p sends each element 0 of array data as a message bit(0). It sends each element 1 of array data as a sequence of two messages bit(1) followed by bit(0). It sends each element 2 of array data as a sequence of three messages bit(1) followed by bit(1) followed by bit(0), and sends each element 3 of array data as a sequence of three messages bit(1) followed by bit(1) followed by bit(1). Assuming that the communication from p to q is error free, specify processes p and q in this protocol using the AP notation. ------------------------------------------------------------------------------- 2. (Error Tolerance: 5 points) The processes in a process array p[i : 0..n-1] are arranged in a unidirectional ring where there is a channel from each p[i] to p[i+1 mod n]. The inputs and variables of each p[i] are specified as follows: process p[0] inp data : array[integer]of integer var i : integer, {index of data, init. 0} bnext : 0..1, {init. 1} ready : boolean, {init. true} t : integer, b : 0..1 begin ready --> [] rcv msg(t,b) from p[n-1] --> [] timeout ~ready ^ (for every j, j in 0..n-1, #ch.p[j].p[j+1 mod n] = 0) --> end process p[i : 1..n-1] var rcvd : array[integer]of integer, i : integer, {index of rcvd, init. 0} blast : 0..1, {init. 1} t : integer, b : 0..1 begin rcv msg(t,b) from p[i-1 mod n]--> end When p[0] is "ready", it generates a message msg(t,b) where t is the value of the next element in array data and b is a sequence number in the range 0..1. Then p[0] sends the message to p[1], and becomes "not-ready". The sent msg(t,b) circulates around the ring, and each p[i : 1..n-1] extracts t from the circulating message and stores in it the next element in its array rcvd. When the circulating message returns to process p[0], p[0] becomes "ready" and it can generate the next msg(t,b). Sent messages can be lost. And when p[0] detects that its last msg(t,b) has been lost, p[0] sends another copy of its last msg(t,b) to p[1]. Thus, each p[i : 1..n-1] can receive multiple copies of the same msg(t,b), but it only needs to store exactly one copy of t in its rcvd array. Specify statements S0 through S3. ------------------------------------------------------------------------------