Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prof. Leonardo Mostarda University of Camerino

Similar presentations


Presentation on theme: "Prof. Leonardo Mostarda University of Camerino"— Presentation transcript:

1 Prof. Leonardo Mostarda University of Camerino
SYNCHRONISATION 2 Prof. Leonardo Mostarda University of Camerino Prof. Leonardo Mostarda-- Camerino,

2 Last lecture Physical Clocks Clock Synchronization Algorithms
Logical clocks

3 Outline MUTUAL EXCLUSION Leader election A Centralized Algorithm
A Distributed Algorithm A Token Ring Algorithm Leader election The Bully Algorithm A Ring Algorithm

4 MUTUAL EXCLUSION In many cases processes will need to simultaneously access the same resources. To prevent that such concurrent accesses corrupt the resource, or make it inconsistent, solutions are needed to grant mutual exclusive access by processes. We take a look at some of the more important distributed algorithms that have been proposed.

5 MUTUAL EXCLUSION Distributed mutual exclusion algorithms can be classified into two different categories. Token-based solutions easy to implement fairness easy to avoid deadlock when token is lost it is difficult to create exactly one new token. Permission-based approach source first requires the permission of other processes

6 MUTUAL EXCLUSION A Centralized Algorithm
The most straightforward way to achieve mutual exclusion in a distributed system is to simulate how it is done in a one-processor system. One process is elected as the coordinator. Whenever a process wants to access a shared resource, it sends a request message to the coordinator. it is fair it guarantees mutual exclusion

7 Mutual Exclusion A Centralized Algorithm (1)
(a) Process 1 asks the coordinator for permission to access a hared resource. Permission is granted.

8 Mutual Exclusion: a Centralized Algorithm (2)
Process 2 then asks permission to access the same resource. The coordinator does not reply.

9 Mutual Exclusion A Centralized Algorithm (3)
When process 1 releases the resource, it tells the coordinator, which then replies to 2.

10 MUTUAL EXCLUSION The coordinator is a single point of failure.
Problems? The coordinator is a single point of failure. Scalability

11 Ricart and Agrawala A Distributed Algorithm
Ricart and Agrawala's algorithm requires that there be a total ordering of all events in the system. Lamport's algorithm presented in Sec is one way to achieve this ordering and can be used to provide time-stamps for distributed mutual exclusion.

12 Ricart and Agrawala When a process wants to access a shared resource, it sends a message containing the name of the resource, its process number, and the current (logical) time to all processes. When a process receives a request message, the action it takes depends on its own state with respect to the resource named in the message. Three different cases have to be clearly distinguished:

13 A Distributed Algorithm (1)
Three different cases: If the receiver is not accessing the resource and does not want to access it, it sends back an OK message to the sender. If the receiver already has access to the resource, it simply does not reply. Instead, it queues the request. If the receiver wants to access the resource as well but has not yet done so, it compares the timestamp of the incoming message with the one contained in the message that it has sent everyone. The lowest one wins.

14 A Distributed Algorithm (2)
(a) Two processes want to access a shared resource at the same moment.

15 A Distributed Algorithm (3)
Process 0 has the lowest timestamp, so it wins.

16 A Distributed Algorithm (4)
When process 0 is done, it sends an OK also, so 2 can now go ahead.

17 MUTUAL EXCLUSION Problems? NACK
We have introduced n points of failure. If any process crashes, it will fail to respond to requests. This silence will be interpreted (incorrectly) as denial of permission, thus blocking all subsequent attempts by all processes to enter all critical regions. Solution? NACK

18 A Token Ring Algorithm (a) An unordered group of processes on a network. (b) A logical ring constructed in software.

19 ELECTION ALGORITHMS Many distributed algorithms require one process to act as coordinator; If all processes are exactly the same, with no distinguishing characteristics, there is no way to select one of them to be special; We will assume that each process has a unique number, for example, its network address; Election algorithms attempt to locate the process with the highest process number and designate it as coordinator. The algorithms differ in the way they do the location.

20 ELECTION ALGORITHMS We assume that every process knows the process number of every other process. What the processes do not know is which ones are currently up and which ones are currently down. The goal of an election algorithm is to ensure that when an election starts, it concludes with all processes agreeing on who the new coordinator is to be.

21 Election Algorithms The Bully Algorithm
P sends an ELECTION message to all processes with higher numbers. If no one responds, P wins the election and becomes coordinator. If one of the higher-ups answers, it takes over. P’s job is done.

22 The Bully Algorithm (1) The bully election algorithm.
(a) Process 4 holds an election. (b) Processes 5 and 6 respond, telling 4 to stop. (c) Now 5 and 6 each hold an election.

23 The Bully Algorithm (2) The bully election algorithm.
(d) Process 6 tells 5 to stop. (e) Process 6 wins and tells everyone. Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved

24 A Ring Algorithm Election algorithm using a ring.

25 Summary MUTUAL EXCLUSION Leader election A Centralized Algorithm
A Distributed Algorithm A Token Ring Algorithm Leader election The Bully Algorithm A Ring Algorithm


Download ppt "Prof. Leonardo Mostarda University of Camerino"

Similar presentations


Ads by Google