0% found this document useful (0 votes)
17 views15 pages

Document 2

The Ricart-Agrawala algorithm is a mutual exclusion method that utilizes a permission-based approach and timestamps to manage access to critical sections in distributed systems. It requires communication in FIFO order and involves sending REQUEST and REPLY messages among sites, with the smaller timestamp requests being prioritized. However, the algorithm has drawbacks such as unreliability due to potential node failures, which can lead to starvation of processes, and it requires a significant number of messages for execution.

Uploaded by

fathimanihla841
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
17 views15 pages

Document 2

The Ricart-Agrawala algorithm is a mutual exclusion method that utilizes a permission-based approach and timestamps to manage access to critical sections in distributed systems. It requires communication in FIFO order and involves sending REQUEST and REPLY messages among sites, with the smaller timestamp requests being prioritized. However, the algorithm has drawbacks such as unreliability due to potential node failures, which can lead to starvation of processes, and it requires a significant number of messages for execution.

Uploaded by

fathimanihla841
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 15
3.4 RICART-AGRAWALA ALGORITHM Ricart-Agrawala algorithm. is anjalgorithm for mutual exclusion proposed by Glenn Ritart and Ashok Agrawala. This algorithm is en extension and optimization of L-amport's *~ Distril futual Exclision Algorithm. | * Tt foltogys petmission based approach to ensure mutual exclusion. “'). - ‘This algotithm requires communication channels to deliver messages in FIFO > order. Types of messages: . 1. REQUEST 5 2. REPLY ~ A site send a REQUEST message to all other site to get their permission to enter critical section. A ‘site-send:a REPLY message to other site to give its permission to enter the critical section, ‘A timestamp is given to each critical section request using Lamport’s logical clock Timestamp is used to determine prictity of critical section requests. Smaller timestamp gets high priority over larger timestamp. The execution of criti¢al section request is always in the order of their timestamp ‘Requesting the critical section ; (2) When 9 site $; wants to enter the CS, it broadcasts a tinseatasaped REQUEST message to all other sites. (©) When site 5, recsives a REQUEST REPLY mestage to site 5, message from sito Sit seods a if ste 5, is neither requesting nor executing Pe CS: oF if the ste, is requesting anil S's soqueat's Ganeatenp ft 1 Gnoltee than site Sys on reotbere, Umentamp. Otherwise, the reply is deferred and 9, acts RD, Ii] so Executing the critical section i (©) Site 5; enters the CS after it has feceived aiREPLY message fromevery site it sent a REQUEST message to Releasing the critieal ssetion { (2) When site 5, exits the (CS, it sends all lthe defend REPLYPmee- Rar, Lf ROU) =1, then sends a REPLY message to $, and acts RD = 0. t Algorithm 9.2 The Reat-Agraala agp, Example: [operation of Ricart-Agrawala algorithm] ‘eres seth posMemenae sy ‘ 4 oo it * =i Se siemnincs 0 etn 5m + In Fig 9.7, Sites $1 and $2 arg each making requests for the CS and sending out REQUEST messages to ole sid, The timestamps ofthe requests are (2.1) and (1.2), respectively. 4+ In Fig. 9.8, S2 has received REPLY messages from all other sites and, consequently, centers the CS. In Fig. 9.9, $2 exits the CS and sends a REPLY mesage to site $1 In Fig. 9.10, sito SI has received REPLY ftom all oter sites and enters the CS,next Properties stifled bythe Rieart-AgravalaAlgorths +. Ricart-Agrawala algorithm achieves mutual exclusion. Performance: ‘Synchronization delay is equal 10 maximum message transmission time It requires 2(N-1) ressages per Critical section execution ‘+ The synchronization delay inthe algorithm iT Drawbacks of Ricart-Agrawala algorithm: * ‘+ Unreliable approach: feilre of any one of node in the system can halt the progress ‘of the system. In this situation, the process will starve forever. 3.S MAEKAWA‘s ALGORITHM ‘Mackawa's Algorithm was the fist quorum based approach. In permission based algorithms fke Lamport’s Algorithm, Ricart-Agrawala Algorithm ee. a site request permission from every other site. B_ Bot in quorum based approach, a site does not request permission from every other site but from a subset of sites which is called quorum, ‘Types of message OD. REQUES' 3. REPLY 3. RELEASE + Aste sends a REQUEST message to all other stein ts request set or quoru 1 get their permission to enter critical section, — 78 + A.site sends a REPLY message to requesting site to give its permission to enter the critical section, * A site sends a RELEASE message to all other site in its request set or quorum upon exiting the critical section, Conditions to be satisfied for Maekawa’s algorithia: Mi (¥i Vjsiejisi, jsNuR,AR, #6) M2 (Wi:lsisN=S,eR,) M3 (Vi:1SisNSIR,|=K) M4 Any site S, is contained in K number of Rs, 1 Deadlock prevention > Deadlock avoidance > Deadlock detection. Deadlock preventi ‘+ Deadlock prevention is commonly achieved by ether having a process acquire all the needed resources simultaneously before it begins execution or by pre-empting a process that holds the needed resource Deadlock avoidance: + In deadlock avoidance, a resource is granted toa proces ifthe resulting global system is safe. Deadlock detection: Deadlock detection requires an examination of the status of the process-resources interaction forthe presence ofa deadlock condition. 3.9.2 ISSUES IN DEADLOCK DETECTION Deadlock handling faces two major issues 1. Detection of existing deadlocks 2 Resolution of detected deadlocks i L Detection of existing deadlocks ‘© Detection of deadlocks involves addressing two issues namely maintenance of the WEG and searching of the WFG for the presence of cycles or knots. ‘© Inistibuted systems, a cycle or knot may involve several sites; the search for cycles greatly depends upon how the WFG of the system is represented across the system. : Depending upon the way WFG information is maintained and the search for eycles is carried out, there are centralized, distributed, and hierarchical algorithms for deadlock detection in distributed systems. : 4 A deadlock detection algorithm must satisfy the following two conditions: 2) Progress-No undetected deadioaks: ‘ * The algorithm must detect all existing deadlocks in finite time, b) Safety -No false deadtocks: 7 ‘© The algorithm should not report deadlocks which do not exist. This i also called as called phantom or false deadlocks. SS 8 TL Resolution of detected deadlocks: . Deadlock resolution involves breaking existing wait-for de mncies | Processes to resolve the deadlock. . : vie a pe +. 2. Involves rolling back one or more deadlocked processes and assigning their ‘Tesources to blocked processes so that they ean resume execution. 2° | The deadiock detection algorithms propagate information regarding wait-for dependencies along the edges ofthe wait-for graph. * When a waitfor dependency is broken, the corresponding information should be immediately cleaned from the system. + If this information isnot cleaned ina timely manner, phantom deadlocks. Ge MODELS OF DEADLOCKS LISINGLE RESOURCE MODEL ‘A process can have at most one outstanding request for only one unit of resource. The ‘maximum out-degree ofa node in a WG forthe single resource model canbe |, the presence of ‘cycle in the WEG shall indicate that there is a deadlock. % R may result in detection of, e % % Fig 3.10: Deadlock in single resource mode! 3.10.2 AND MODEL 5 Tn the AND model, a process can request more than one resource simultaneously and the request is satisfied only afterall the requested resources are granted tothe process. The requested resources may exist at different locations. '* The out degree of a node in the WEG for AND model can be more than 1 ‘+ The presence ofa cycle in the WFG indicates a deadlock inthe AND model 2 Each node ofthe WEG in such a inode is called an AND node. ‘+ Inthe AND model fa cycle is detected in the WFG, it implies a deadlock but nat vice versa That is, a process may not bea part ofa cycle, itcan sill be deadlocked. + In Fig. 10.1. Process P1l has two outstanding resource AND model, P11 shall become ative from idle state only aftr ae granted, There is a cycle Pl I=9P21+P24—+PS4—~PI 1, which: a deadlock situation. Ry + Consider process P44 in Figure 10.1. It is not « part of any eyele but deadlocked as itis dependent on P24. : 3.10.3 OR MODEL |n OR model, a process can make a request for numerous resources simultaneously request is satisfied if ny one ofthe requested resourees is granted, The requested resources exist at different locations + [fall requests in the WFG are OR requests, then the nodes are called OR nodes, _ + Presence of a cycle in the WFG of an OR model does not imply a deadlock in the © + Inthe OR model, the presence of a knot indicates oc Deadlock in OR model: be satisfied. ith every blocked process, there is an associated set of processes called A process shall move from an ide to an active state on receiving a grant any ofthe processes in its dependent set. ‘ process i permanently blocked if itmever receives a grant message from ary processes in its dependent set, i +e As of processes S is deadlocked if all the processes in $ are permanently | nore Proves is deadlocked or permanently blocked, ithe following 1. Each of the process is the set S is blocked. 2. The dependent set for each process in $ is a subset of S. 3. No grant message is in transit between any two processes in set S ‘+ A blocked process P js the set S becomes active only after receiving a grant message from a process in its dependent set, which is a subset of S. © Consider Figure 10.1. If all nodes are OR nodes, then process PI is no deadlocked because once process P33 releases its resources, P32 shall become active as one of its requests is satisfied. After P32 finishes execution and releases its’ resources, process P11 can continue with its processing, ‘* Where P44 can be deadlocked even though it is not in a knot. So, in an OR model, a blocked process P is deadlocked if itis either in a knot or it can only reach processes on a knot. 3.10.4 THE AND-OR MODEL + A generalization of the previous two models (OR model and AND model) is the AND- ‘OR model. In the AND-OR model, a request may specify any combination of and and or in the resource request. For example, in the ANDOR model, a request for multiple resources can be of the form x and (y oF 2). ‘+ The requested resources may exist at different locations. Deadlock can be detected by repeated application of the test for OR-model deadlock. 3.105 TBE @ MODEL [P OUT OF Q MODEL): This is a variation of AND-OR model. This allows # request to obiain any k available resources from a pool of n resources. Both the models are the same in expressive power, ‘This favours more compact formation of a request. + Every request in this model can be expressed in the AND-OR model and vice- versa. * Note that AND requests for p resources cane stated © (P) as andOR requests for p resources can be stated . q. 3.10.6 UNRESTRICTED MODEL * No assumptions are made regarding the underlying structure of resource requests. + Inthis model, only one assumptiod that the deadlock is stable is made and hence it is the most general model.) 3.13 THE AND MODEL AND THE OR MODEL ©3.13:1 CHANDY-MISRA-HAAS ALGORITHM FOR THE AND MODEL | Data structures Each process P; maintains a boolean array, dependent, where dependent; (j) is true only if This is based on edge-chasing, probe-based algorithm. j This algorithm uses a special message called probe, which is a triplet (ijk), denoting that it belongs to a deadlock detection initiated for process P, andit is being sent by the home site of process Pj to the home site of processPx. Each probe message contains the following information: > the id of the process that is blocked (the one that initiates the probe message) > the id of the process is sending this particular version of the probe message. > the id of the process that should receive this probe message. A probe message travels along the edges of the global WFG graph, and a deadlock is detected when a probe message returns to the process that initiated it. A process P, is said to be dependent on another process Py if there exists a sequence of processes Pj, Pir, Piz, ..., Pim, Px such that each process except Px in the sequence is blocked and each process, except the Pj, holds a resource for whieh the previous provess in the sequence is waiting. Process P; is said to be locally dependent upon process Py if P, is dependent upon Pyand both the processes are on the same site. | Piknows that Pj is dependent on it. Initially, dependent; (j) is false for all i and j. 90 a ee, IF, is locally dependent on itself ‘hen declare a deadlock else forall P; and Py such that (e) P, is locally dependent upon P,. and (0) P, is waiting on P,, and (©) Py and Py are on diferent sites. send a probe (i, j, 4) to the home site of Py (On the receipt of probe (i,j, A) the site takes the following actions: it (a) P, is blocked, and (6) dependent,() is fase, and 3 (0 P, bas not replied to all requests P, then begin dependent,()) = true; irk, ; then declare that P, is deadlocked. lse,for all Py add P, such that (@) Ay is locally dependent upon Py and (b) By is waiting on P,, and (©) Py and P, are on different sites, send a probe (i,m, n) to the home site of P, nd. 3 Algorithm 10.1 Chandy-Miso-tas algo forthe AND moda aL. Performance analysi ‘In the algorithm, one probe message is sent on every edge of the WFG which connects processes on two sites, + The algorithm exchanges at most rh(n~ 1)/2 messages to detect a deadlock that involves m processes and spans over n sites. +The size of messages i fixed and ib very small (only three integer words). + The delay in detecting a deadlock is O(n), Advantages: + Itis easy to implement. Each probe message is of fixed length. There is very little computation, There is very litte overhead There is no need to construct a graph, nor to pass graph information to other sites, This algorithm does not find false (phantom) deadlock, 9 3.132; CHANDY-MISRA-HAAS ALGORITHM FOR THE OR MODEL se dealt bnse4 on the approach of diffusion computation. A blocked proces determines if it {is deadlocked by initiating a diffusion computation. + Two pes of messages are used in a'iffusion computation > query, j k) > reply, jk) denoting that they belong to # diffusion computation initiated by a process pand are being sent from process pto process py ee Wi Initiate @ diffusion computation for a blocked process P; send query(, i, j) to all processes P, in the dependent set DS, of P;: num (i) == |DSil3 wait) := true; When a blocked process P, receives a query(i, j,k): if this is the engaging query for process P, then in its dependent set DS,; true else if wait,() then vend a reply(i,k, /) to P, When a process P, receives a reply(i,j, 8): if waing(?) then num (f)- = nim (i) if mum, (2) = 0 then if =k then declare a deadlock else send reply(i, k, m) to the process P,, ‘which sent the engaging query. Algorithm 10.2. Chand-éra-Haas alot forthe OR made! (6, ‘+ A blocked process initiates deadlock detection by sending query messages toall processes inits dependent ‘If an active process receives x Gury or reply message, it discards it * When a blocked process Pk receives a query(i j,k) message, it takes the following actions: 1, If this isthe frst query message received by Pk for the deadlock detection initited by Pi, then it propagates the query to all the processes in its dependent set and sets a local variable num (i) tothe number of query messagessent. 2. If this is not the engaging query, then Pk retums a reply message to it immediately provided Pk has been continuously blocked since it received the corresponding engaging query. Otherwise, it discards the query, —rorr— 2

You might also like