[Q.1] It is assumed that in Lamport’s Distributed Algorithm that all sites have equal priority and
therefore each site broadcasts its request to access critical section to all other sites. In this
question you have to improvise Lamport’s Distributed Mutual Exclusion Algorithm by prioritizing
the sites. Each site is assigned a unique integer number ‘n’ (>=1 and <=K where K is the
number of sites in the system) which duly represents the priority as well as the ID of the
process. The priority of site decreases with the increase in the value of ‘n’ [i.e. priority value ‘1’
means highest, ‘2’ means second highest and so on]. The algorithm designed by you should
fulfill the following requirements:
a. When there are simultaneous requests for the critical section, for multiple sites, then the
higher priority sites should be given preference over the lower priority sites subject to the
condition that lower priority sites should not starve for the critical section.
b. Any site can enter the critical section only after making a request for critical section.
c. The algorithm should be deadlock free.
Design the algorithm to satisfy above requirements. Before writing the algorithm, you have to
mention which data structure you are going to use and what is the role of each. Your algorithm
should have the following four sections:
1) Initialization
2) Requesting Critical Section
3) Executing Critical Section
4) Releasing Critical Section
Posts: 6,843
Threads: 4
Joined: Mar 2015
java code lamport s mutual exclusion algorithm
DAJ is an interactive, visual aid for studying distributed algorithms. Interactive, because you must explicitly specify every step of the interleaved execution sequence. Visual, because the state of the nodes is continuously displayed. Study aid, because they solve one of the most difficult problems encountered by students of these algorithms by automatically doing the necessary book-keeping. The program can create a log file of commands so that you can automatically replay scenarios until you understand them. Fourteen algorithms are current implemented, and you can implement other algorithms with only an elementary knowledge of Java. Visualizations are included for the virtual global structures contructed by some of the algorithms.
Lamport's bakery algorithm is a computer algorithm devised by computer scientist Leslie Lamport, which is intended to improve the safety in the usage of shared resources among multiple threads by means of mutual exclusion.
In computer science, it is common for multiple threads to simultaneously access the same resources. Data corruption can occur if two or more threads try to write into the same memory location, or if one thread reads a memory location before another has finished writing into it. Lamport's bakery algorithm is one of many mutual exclusion algorithms designed to prevent concurrent threads entering critical sections of code concurrently to eliminate the risk of data corruption.
Algorithms implemented
Byzantine generals algorithm for consensus (byzantine failures).
Byzantine generals algorithm for consensus (crash failures).
Byzantine generals algorithm for consensus by Berman and Garay (Algorithm 5.2 of Attiya and Welch).
EIGStop algorithm for consensus (Section 6.2.3 of Lynch).
Ricart-Agrawala algorithm for mutual exclusion.
Suzuki-Kasami algorithm for mutual exclusion.
Neilsen-Mizuno algorithm for mutual exclusion.
Lamport algorithm for mutual exclusion.
Maekawa algorithm for mutual exclusion.
Carvalho-Roucairol algorithm for mutual exclusion.
Dijkstra-Scholten algorithm for detecting termination.
Chandy-Lamport algorithm for global snapshots.
Huang algorithm for termination detection.
Mattern algorithm for termination detection.