You are on page 1of 6

CS 6378, Spring 2005

Mid Term 2. March 29, 2005

Student Name: ID #:

Important:
a. This examination has 4 questions for total of 20 points. Duration: 75
minutes.
b. Talk to me during exam before making any assumptions of your own.
c. State your assumptions explicitly in your answer.
d. Brief descriptions of the algorithms are given separately.
e. You may use the blank page on the left-hand side as well as at the end.

1. We briefly talked about the Greedy approach in Raymond’s algorithm for distributed mutual
exclusion:
“Intermediate site getting the token may enter CS instead of forwarding it down the tree.”
Will the greedy approach lead to starvation? If yes, specify the conditions that will lead to
starvation by giving an example. If no, show why the greedy approach will not lead to starvation.
(Either way, keep your answer short).
(5 Marks)

In the greedy approach, the site getting the token does not look at the Q and uses the token if it
has an outstanding CS request. Now, if this site keeps having CS requests all the time, other sites
will never get the token.

Hence, it can lead to starvation: if a site (or a set of sites) getting the token, has continuous CS
requests/executions.

1

2. (5 Marks) Coordinator Cohort i q1 qi C_R received/ C_R received/ Commit_Request Agreed msg sent Abort msg sent F. then assign a failure transition from s to a commit state in its FSA. So Pi –T Ci.T message sent to all cohorts F. pi) in the protocol.T send Ack T Abort from P1 coordinator a1 Pi Abort to all All cohorts cohorts F Commit Ack/ Send Commit F. 2 . Rule for timeout transition: For each nonfinal state s.T: Failure/Timeout For Pi: S(s) is the coordinator. Otherwise. The complete 3-phase commit protocol diagram below. Consider P1 and Pi. So.T received from msg to all coordinator c1 F: Failure Transition ci T: Timeout Transition F. Coordinator is waiting for Ack from a cohort. For P1: S(s) is cohort. if C(s) contains a commit. Wi –F ai.T F. Coordinator will be in P1 at this time since cohort is expecting Commit message (and this message can be sent only from P1).. wi. assign a failure transition from s to an abort state. P1 –T a1. Rule for failure transition: For every non-final state s (i. So that cohrt (on which the coordinator is waiting) should be in Wi. P1 has a time-out transition to a1 whereas P i times out to ci. P1 –F C1.and site j has a failure transition from s to a commit (abort) state. if site j in S(s).T wi w1 All agreed/ Abort from ai One or more abort Prep msg Prepare msg coordinator reply/ Abort msg received/ to all sent to all cohorts F. qi. then assign a timeout transition from s to a commit (abort) state. Explain how time-out transition for P1 goes a1 and how it goes to c i for Pi. You have to use the above rules and explain.e.

Do you think this algorithm will work? If not. (5 Marks) Problems with the algorithm: Let’s say Sk sends REQUEST to Sj. So. Sk will have to forward its request to Sx or Sj would have to forward (to Sx) on behalf of Sk.3. assume that Sj gives the token to Sx. If token comes to a site. If token moves out Sx to Sy (before the forwarded request arrives at Sx). Now Sx broadcasts that it is the holder. Before Sj gets the request. this forwarding might have to be done repeatedly. In Suzuki-Kasami algorithm. what else would have to be done? Can you explore this approach from the following parameters view: starvation. the site that needs to get into critical section (CS) broadcasts a REQUEST for Token. Let us say Sj gets the token from Si. Then Sj will broadcast the message “I Am The Token Holder”. Using sequence number for requests. (Of course. it gets added to this Q even if the site does not have the token. and fairness? Give your views on the “new” algorithm to that student with respect to these parameters. we assume that no sites. It is possible to prevent starvation though: by having a Q of requests in each site. 3 . this algorithm has to identify duplicate and obsolete requests. One student asked me whether it will be advantageous to do the other way: Let the site having the Token broadcast a message saying “I Am The Token Holder”. including the token holder. Now. Any site trying to enter CS will send the REQUEST directly to the Token Holder. Another site Sk requiring the token will send the REQUEST message directly to Sj. this Q can be used to determine which site should get the token next. fairness cannot be ensured obviously. crash). And whenever a REQUEST is received.

(5 Marks) P1 P2 P5 P3 P4 P1 can detect the deadlock: it sends 1 query and receives 1 reply.4. 4 . will P1 be able to detect a deadlock? Explain your answer briefly. If the Probe message is initiated by P1. Consider the following Wait-for-graph (WFG). we saw that the edge-chasing algorithm will not let P1 declare a deadlock. Is it the same way for diffusion-based algorithm also? Is there a deadlock in this WFG for OR request model? If so.

waiti(i) := true. if a sequence of Pj.m.j..j) to Pj. else if waitk(i) then send a reply(i.k) to the home site of Pk.n) to the home site of Pn. and (b’) Pm is waiting on Pn. Diffusion-based Algorithm Initiation by a blocked process Pi: send query(i. num(i) := |DSi|. and (b) Pj is waiting on Pk. end. and (c ) Pj and Pk are on different sites. This probe is sent by the home site of Pj to Pk. 2.  This probe message is circulated via the edges of the graph. k) is used by a deadlock detection process Pi. 3. else for all Pj and Pk such that (a) Pi is locally dependent upon Pj. Probe returning to Pi implies deadlock detection. Sending the probe: if Pi is locally dependent on itself then deadlock. and (c’) Pm and Pn are on different sites. waitk(i) := true. (initially set to false for all i & j). j. m) to Pm. send probe(i. Pi1. broadcast a REQUEST for token message to all other sites. Pk exists.1. numk(i) := |DSk|.  Pj is locally dependent on Pk.k): if this is engaging query for process Pk /* first query from Pi */ then send query(i. and (f) Pk has not replied to all requests of Pj. send probe(i.Brief Descriptions of Algorithms 1. which sent the engaging query. if numk(i) = 0 then if i = k then declare a deadlock.j.k.Pk on same site.k. Blocked process Pk receiving query(i. Chandy-Misra-Haas’s Edge-Chasing Algorithm:  A probe(i. Receiving the probe: if (d) Pk is blocked. and (e) dependentk(i) is false.. else send reply(i.i.j) to all processes Pj in the dependent set DSi of Pi. k. if k = i then Pi is deadlocked else for all Pm and Pn such that (a’) Pk is locally dependent upon Pm..m) to all Pm in DSk. if above condition + Pj.j. 5 . Process Pk receiving reply(i.k) if waitk(i) then numk(i) := numk(i) .  Each process maintains an array dependenti: dependenti(j) is true if Pi knows that Pj is dependent on it. Pim. then begin dependentk(i) := true. Suzuki-Kasami Algorithm  If a site without a token needs to enter a CS.  Terms used:  Pj is dependent on Pk.

Raymond’s Algorithm  Sites are arranged in a logical directed tree. sends after exiting CS. If so.  Site on path to root receiving REQUEST -> propagate it up. 6 .  Requesting CS  If Si does not hold token and request CS.  If request_q is non-empty now.  Send token to the site at head of Q.  Each site has RNi[1.  Root on receiving REQUEST -> send token to the site that forwarded the message.  Any Si receiving token -> delete top entry from request_q. send token to that site. send REQUEST message to the holder site.n) -> jth site making nth request. place j in Q. on the directed path towards root.  Releasing CS  If request_q is non-empty. sends REQUEST upwards provided its request_q is empty.  Token: (a) Queue of request sites (b) Array LN[1..  Determining which site has an outstanding token request. if its request_q is empty. (Root’s holder point to itself). 4. set holder to that site.  If LN[j] = RNi[j] . set holder to point to it.N]. It then adds its request to request_q.  Executing CS: getting token with the site at the top of request_q. Otherwise.  Token holder checks if RNi[j] = LN[j] + 1. delete top entry from q. the sequence number of the most recent execution by a site j.  Every site has a variable holder that points to an immediate neighbor node.. enter CS. Add request to request_q.N] -> RNi[j] is the largest sequence number of request from j. Root: token holder.1. Q is a queue of requesting sites. Affects fairness. LN[i] := RNi[i]  Token consists of Q and LN.  Format: REQUEST(j.  Design issues:  Distinguishing outdated REQUEST messages.  Passing the token  After finishing CS  (assuming Si has token). then Sj has an outstanding request.  Token holder can make multiple CS accesses.  Non-empty request_q -> REQUEST message for top entry in q (if not done before). if it is not inside CS. send REQUEST message to the holder site. may cause starvation. Greedy approach: Intermediate site getting the token may enter CS instead of forwarding it down. Edges: directed towards root. Set holder to that forwarding site. If request_q is non-empty now. Delete top of request_q. send token to that site.  Token holder sends token to requestor.