Docsity

Mutual Exclusion Algorithms: Centralized, Token Ring, Ricart-Agrawala, Lamport, Slides of Operating Systems

Partial preview of the text

Download Mutual Exclusion Algorithms: Centralized, Token Ring, Ricart-Agrawala, Lamport and more Slides Operating Systems in PDF only on Docsity!

Distributed Systems

Mutual Exclusion

Mutual Exclusion?

  • A condition in which there is a set of processes, only one of which is

able to access a given resource or perform a given function at any

time

Distributed Mutual Exclusion

  • Assume there is agreement on how a resource is identified
    • Pass identifier with requests
  • Create an algorithm to allow a process to obtain exclusive access to a

resource

Distributed Mutual Exclusion

  • Centralized Algorithm
  • Token Ring Algorithm
  • Distributed Algorithm
  • Decentralized Algorithm

Centralized algorithm

If another process claimed resource:

  • Coordinator does not reply until release
  • Maintain queue
    • Service requests in FIFO order P

C request(R) grant(R) release(R) P

P

request(R)

Queue

P

request(R) P

grant(R)

Centralized algorithm

Benefits

  • Fair
    • All requests processed in order
  • Easy to implement, understand, verify

Problems

  • Process cannot distinguish being blocked from a dead coordinator
  • Centralized server can be a bottleneck

Token Ring algorithm

  • Initialization
    • Process 0 gets token for resource R
  • Token circulates around ring
    • From Pi to P(i+1)mod N
  • When process acquires token
    • Checks to see if it needs to enter critical section
    • If no, send token to neighbor
    • If yes, access resource
      • Hold token until done P 0 P 1 P 2 P 3 P 4 P 5 token(R)

Token Ring algorithm

  • Only one process at a time has token
    • Mutual exclusion guaranteed
  • Order well-defined
    • Starvation cannot occur
  • If token is lost (e.g. process died)
    • It will have to be regenerated
  • Does not guarantee FIFO order

Ricart & Agrawala algorithm

  • When process receives request:
    • If receiver not interested:
      • Send OK to sender
    • If receiver is in critical section
      • Do not reply; add request to queue
    • If receiver just sent a request as well:
      • Compare timestamps: received & sent messages
      • Earliest wins
      • If receiver is loser, send OK
      • If receiver is winner, do not reply, queue
  • When done with critical section
    • Send OK to all queued requests

Ricart & Agrawala algorithm

  • N points of failure
  • A lot of messaging traffic
  • Demonstrates that a fully distributed algorithm is possible

Lamport’s Mutual Exclusion

Entering critical section (accessing resource):

  • Pi received a message ( ack or release ) from every other process with a timestamp larger than Ti
  • Pi’s request has the earliest timestamp in its queue

Difference from Ricart-Agrawala:

  • Everyone responds … always - no hold-back
  • Process decides to go based on whether its request is the earliest in its queue

Lamport’s Mutual Exclusion

Releasing critical section:

  • Remove request from its own queue
  • Send a timestamped release message
  • When a process receives a release message
    • Removes request for that process from its queue
    • This may cause its own entry have the earliest timestamp in the queue, enabling it to access the critical section

Decentralized Algorithm

  • Based on the Distributed Hash Table (DHT) system structure

previously introduced

  • Peer-to-peer
  • Object names are hashed to find the successor node that will store them
  • Here, we assume that n replicas of each object are stored

Placing the Replicas

  • The resource is known by a unique name: rname
    • Replicas: rname-0, rname-I, …, rname-(n-1)
    • rname-i is stored at succ(rname-i) , where names and site names are hashed as before
    • If a process knows the name of the resource it wishes to access, it also can generate the hash keys that are used to locate all the replicas