Giter VIP home page Giter VIP logo

maekawa's Introduction

Maekawa Algorithm

Introduction

Maekawa algorithm is a distributed mutual exclusion algorithm that allows a group of nodes or sites to coordinate access to a shared resource in a distributed system. It is a variation of the Ricart-Agrawala algorithm and is used to ensure that only one process at a time can access the shared resource, while allowing other processes to proceed concurrently as long as they do not require access to the shared resource. It works by using a token that is passed among the processes in the system. When a process wants to access the shared resource, it sends a request message to all other processes in the system. If a process has the token, it immediately sends the token to the requesting process and the requesting process can access the shared resource. If a process does not have the token, it sends an acknowledgement message back to the requesting process and adds itself to a queue of processes waiting for the token. When the requesting process is finished with the shared resource, it sends the token to the next process in the queue, allowing that process to access the shared resource. This process continues until all processes have had an opportunity to access the shared resource.

Implementation

alt text

In our case each node acts both as client and server.

Client

In the client side, there is a main method called update() that executes indefinetly the following 3 methods

  • request critical section()
  • enter critical section()
  • exit critical section()
update():
  self.node.signal_request_cs.wait()
  self.node.request_cs(datetime.now())
  self.node.signal_enter_cs.wait()
  self.node.enter_cs(datetime.now())
  self.node.signal_exit_cs.wait()
  self.node.exit_cs(datetime.now())

Server

The server side handles the requests in a method called process_message() that depending on the type of message, executes the corresponding method.

process_message():
  if msg.msg_type == MSG_TYPE.REQUEST:
      self._on_request(msg)
  elif msg.msg_type == MSG_TYPE.GRANT:
      self._on_grant()
  elif msg.msg_type == MSG_TYPE.RELEASE:
      self._on_release()
  elif msg.msg_type == MSG_TYPE.FAIL:
      self._on_fail(msg)
  elif msg.msg_type == MSG_TYPE.INQUIRE:
      self._on_inquire(msg)
  elif msg.msg_type == MSG_TYPE.YIELD:
      self._on_yield()

References

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.