CSE 480 Lecture Notes February 29, 1996 Mutual Exclusion - critical section problem: disable interrupts, semaphores, critical regions, monitors + A Centralize Algorithm (Fig. 3-8) Coordinator loop recv msg case msg of REQUEST: if nobody in CS then reply GRANTED else queue the REQ; reply DENIED RELEASE: if queue not empty then remove 1st on the queue reply "GRANT" end case end loop Client send(REQUEST) recv(msg) if msg = GRANTED then enter CS else recv(msg); enter CS send(RELEASE) - guarantees mutual exclusion - fair (FCFS) - a single point of failure (Coordinator) - if not explicit DENIED msg, then cannot distinguish permission denied from a dead coordinator + A Distributed Algorithm - Lamport Algorithm, Ricart-Agrawala Algorithm - assume total ordering on msgs - msgs are reliable (e.g., every msg acked) - when a process wants to enter a CS, it builds a msg containing the name of CS, process id, current time Algorithm (handout, pp. 128-129 [SiSh94]) Examples: Fig. 3-9, Fig. 6-7,..,6-10 Theorem. The Ricart-Agrawala Algorithm achieves mutual exclusion. Proof: By contradiction. Suppose two sites Si and Sj are in CS concurrently. WLOG, assume that Si has earlier timestamp than Sj. That is, Si received Sj's request after Si made its own request. Thus, Sj can concurrently execute the CS with Si only if Si returns a REPLY to Sj before Si exits the CS. But, this is impossible since Sj has later timestamp than Si. - 2(N-1) msgs: (N-1) request and (N-1) reply msgs - n points of failure (i.e., each process becomes point of failure) can use explicit ack and timeout to detect failured processes - each process need to maintain group membership; non-trivial for large and/or dynamically changing memberships - n bottlenecks since all processes involved in all decisions - may use majority votes to improve the performance + A Token Ring Algorithm - Fig. 3-10 - if the token is lost, it needs to be regenerated. - detection is difficult since there is not bound on how long a process should wait for the token. - if a process can fail, it needs to be detected and by-passed.