Sunteți pe pagina 1din 6

Ricart-Agrawala Algorithm

This is an optimization of Lamports algorithm that dispenses with RELEASE messages by merging them with REPLY messages. Assumptions:

Error-free underlying communication network Transit times may vary Messages may not be delivered in the order sent Nodes are operated correctly

For all i, request set Ri={S1,S2,......,SN}

Requesting CS:

To enter CS, a site Si sends a timestamped REQUEST message to all sites in its request set. When a site Sj receives a REQUEST message from site Si, it sends a REPLY message to site Si if site Sj is neither requesting nor executing CS or if site Sj is requesting and Sis requests timestamp is smaller than site Sjs own requests timestamp. The request is deferred otherwise.

Executing CS:

Site Si enters CS after receiving all REPLY messages

Releasing CS:

Upon exiting CS, it sends REPLY messages to all the deferred requests.

Characteristics of the Algorithm

All requests are totally ordered: mutual exclusion is guaranteed. A sites REPLY messages are blocked only by sites that are requesting CS with higher priority (i.e. a smaller timestamp). Fully distributed control Deadlock free Starvation free Need not require the orderly delivery of the communication system.

Correctness Proof

By contradiction: suppose two sites Si and Sj are executing the CS concurrently and Sis request has a smaller timestamp. Clearly, Si received Sjs request after it had made its own request (otherwise, Sis request would have a larger timestamp). Thus, Sj can concurrently execute CS with Si only if Si returns a REPLY message to Sj before Si exits CS. This is impossible because Sjs request has a larger timestamp. Hence, mutual exclusion is guaranteed.

Performance and Optimization


Number of messages required 2(N-1) messages per CS invocation. Synchronization delay: T Optimization:

By observing that once a site Si has received a REPLY message from a site Sj, the authorization implicit in this message remains valid until Si sends a REPLY message to Sj. Therefore, after site Si has received a REPLY message from site Sj, Si can enter CS any number of times without requesting permission from site Sj, until Si sends a REPLY message to Sj.

Other Modifications

Implicit reply: if message transmission time between nodes has an upper bound, then no REPLY message within that time period implies implicit reply. Broadcast messages: reduced to N messages per CS invocation as there is one REQUEST message plus (N-1) REPLY messages.

Ring structure: the REQUEST message is echoed around the ring and when the requesting message is received at the initiating node, CS processing may begin. Number of messages required is N.

S-ar putea să vă placă și