---------------------------------------------------------------------------- Mohamed G. Gouda CS 356 Midterm # 1 (1 hour and 15 minutes) Fall 2005 ---------------------------------------------------------------------------- 1. [8 points] Consider a protocol that consists of three processes p[i:0..2]. Each process p[i] has a variable ready whose value is in the range 0..2 and whose initial value is 2. When p[i] is ready, it sends two rqst messages to two other processes, and becomes not ready. Then when p[i] receives two rply messages from the two other processes, p[i] becomes ready and the cycle repeats. Specify process p[i:0..2] in the protocol. ---------------------------------------------------------------------------- 2. [12 points] A resource allocation protocol consists of n user processes u[i:0..n-1] and one controller process c. There is only one resource. Each user u[i] can send a rqst message to process c requesting to access the resource. When process c receives a rqst message from u[i], and the resource is not available, c sends a rjct message to u[i]. When process c receives a rqst message from u[i], and the resource is available, c sends a grant message to u[i]. When u[i] receives a grant message from c, it accesses the resource and then sends a rls message to process c. When process c receives a rls message from u[i], the resource becomes available, and c sends an ack message to u[i] to indicate that c has received the rls message from u[i]. When u[i] receives an ack message from c, u[i] can now request the resource again and the cycle repeats. Assume that all sent messages can be lost but not corrupted or reordered. At any instant, user u[i] is in one of four states, and u[i] stores its state in a variable called st, whose value is in the range 0..3. * If st=0, u[i] can request to access the resource. * If st=1, u[i] is waiting to receive a rjct or grant message from c. * If st=2, u[i] accesses the resource and can release it. * If st=3, u[i] is waiting to receive an ack message from c. Process c has a variable usr where it stores the identity of the user to which c has granted the resource last. Process u[i] and process c can be specified as follows. process u[i:0..n-1] var st : 0..3 {0, initially} begin st=0 -> st := 1; send rqst to c [] rcv rjct from c -> st := 0 [] rcv grant from c -> st := 2 [] st=2 -> st := 3; send rls to c [] rcv ack from c -> st := 0 [] timeout G -> S end process c const n var avail : boolean, {true, initially} usr : 0..n-1 par i : 0..n-1 begin rcv rqst from u[i] -> if avail v usr=i -> avail,usr := false,i; send grant to u[i] [] ~avail ^ usr~=i -> send rjct to u[i] fi [] rcv rls from u[i] -> S' end Specify the timeout guard G and statements S in the timeout action of process u[i], and specify the statements S' in the second receiving action of process c. ----------------------------------------------------------------------------