token-passing algorithms for mutual exclusion

21
Token-passing Algorithms for mutual exclusion Suzuki-Kasami algorithm The Main idea Completely connected network of processes There is one token in the network. The holder of the token has the permission to enter CS. Any other process trying to enter CS must acquire that token. Thus the token will move from one process to another based on demand. I want to enter CS I want to enter CS

Upload: stamos

Post on 10-Feb-2016

63 views

Category:

Documents


0 download

DESCRIPTION

Suzuki-Kasami algorithm The Main idea Completely connected network of processes There is one token in the network. The holder of the token has the permission to enter CS. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Token-passing Algorithms for mutual exclusion

Token-passing Algorithms for mutual exclusion

Suzuki-Kasami algorithmThe Main idea

Completely connected network of processes

There is one token in the network. The holder of the token has the permission to enter CS.

Any other process trying to enter CS must acquire that token. Thus the token will move from one process to another based on demand.

I want to enter CSI want to enter CS

Page 2: Token-passing Algorithms for mutual exclusion

Suzuki-Kasami Algorithm

Process i broadcasts (i, num)

Each process maintains-an array req: req[j] denotes the sequence no of the latest request from process j(Some requests will be stale soon)

Additionally, the holder of the token maintains-an array last: last[j] denotes the sequence number of the latest visit to CS from for process j.- a queue Q of waiting processes req: array[0..n-1] of integer

last: array [0..n-1] of integer

Sequence number of the request

req

req

req

req

reqlast

queue Q

Page 3: Token-passing Algorithms for mutual exclusion

Suzuki-Kasami AlgorithmWhen a process i receives a request (k, num) from process k, it sets req[k] to max(req[k], num). The holder of the token

--Completes its CS--Sets last[i]:= its own num--Updates Q by retaining each process k only if1+ last[k] = req[k] (This guarantees the freshness of the request)--Sends the token to the head of Q, along withthe array last and the tail of Q

In fact, token (Q, last)

Req: array[0..n-1] of integer

Last: Array [0..n-1] of integer

Page 4: Token-passing Algorithms for mutual exclusion

Suzuki-Kasami’s algorithm{Program of process j}Initially, i: req[i] = last[i] = 0* Entry protocol *req[j] := req[j] + 1Send (j, req[j]) to allWait until token (Q, last) arrivesCritical Section* Exit protocol *last[j] := req[j]k ≠ j: k Q req[k] = last[k] + 1 append k to Q;if Q is not empty send (tail-of-Q, last) to head-of-Q fi

* Upon receiving a request (k, num) *req[k] := max(req[k], num)

Page 5: Token-passing Algorithms for mutual exclusion

Example

0

2

1

34

req=[1,0,0,0,0]last=[0,0,0,0,0]

req=[1,0,0,0,0]

req=[1,0,0,0,0]

req=[1,0,0,0,0]

req=[1,0,0,0,0]

initial state: process 0 has sent a request to all, and grabbed the token

Page 6: Token-passing Algorithms for mutual exclusion

Example

0

2

1

34

req=[1,1,1,0,0]last=[0,0,0,0,0]

req=[1,1,1,0,0]

req=[1,1,1,0,0]

req=[1,1,1,0,0]

req=[1,1,1,0,0]

1 & 2 send requests to enter CS

Page 7: Token-passing Algorithms for mutual exclusion

Example

0

2

1

34

req=[1,1,1,0,0]last=[1,0,0,0,0]Q=(1,2)

req=[1,1,1,0,0]

req=[1,1,1,0,0]

req=[1,1,1,0,0]

req=[1,1,1,0,0]

0 prepares to exit CS

Page 8: Token-passing Algorithms for mutual exclusion

Example

0

2

1

34

req=[1,1,1,0,0]req=[1,1,1,0,0]last=[1,0,0,0,0]Q=(2)

req=[1,1,1,0,0]

req=[1,1,1,0,0]

req=[1,1,1,0,0]

0 passes token (Q and last) to 1

Page 9: Token-passing Algorithms for mutual exclusion

Example

0

2

1

34

req=[2,1,1,1,0]

req=[2,1,1,1,0]last=[1,0,0,0,0]Q=(2,0,3)

req=[2,1,1,1,0]

req=[2,1,1,1,0]

req=[2,1,1,1,0]

0 and 3 send requests

Page 10: Token-passing Algorithms for mutual exclusion

Example

0

2

1

34

req=[2,1,1,1,0]req=[2,1,1,1,0]

req=[2,1,1,1,0]last=[1,1,0,0,0]Q=(0,3)

req=[2,1,1,1,0]

req=[2,1,1,1,0]

1 sends token to 2

Page 11: Token-passing Algorithms for mutual exclusion

Raymond’s tree-based algorithm

123

45

6 7

1,4 4,7

1

1

4

1,4,7 want to enter their CS

Page 12: Token-passing Algorithms for mutual exclusion

Raymond’s Algorithm

123

45

6 71,4 4,7

1

4

2 sends the token to 6

Page 13: Token-passing Algorithms for mutual exclusion

Raymond’s Algorithm

123

45

6 7

4

4,7

4

The message complexity is O(diameter) of the tree. Extensive empirical measurements show that the average diameter of randomly chosen trees of size n is O(log n). Therefore, the authors claim that the average message complexity is O(log n)

6 forwards the token to 1

4These two directed edges will

reverse their direction

Page 14: Token-passing Algorithms for mutual exclusion

Distributed Snapshot

Page 15: Token-passing Algorithms for mutual exclusion

Distributed snapshot

-- How many messages are in transit

on the internet?

-- What is the global state of a distributed

system of N processes?

How do we compute these?

Page 16: Token-passing Algorithms for mutual exclusion

Think about these

-- How many messages are in transit

on the internet?

-- What is the global state of a distributed

system of N processes?

How do we compute these?

Page 17: Token-passing Algorithms for mutual exclusion

One-dollar bank

0

1

2

(0,1)

(1,2)(2,0)

Let a $1 coin circulate in a network of a million banks.

How can someone count the total $ in circulation? If

not counted “properly,” then one may think the total $

in circulation to be one million.

Page 18: Token-passing Algorithms for mutual exclusion

Importance of snapshots

Major uses in

- deadlock detection

- termination detection

- rollback recovery

- global predicate

computation

Page 19: Token-passing Algorithms for mutual exclusion

Consistent cut

(a consistent cut C) (b happened before a) b CIf this is not true, then the cut is inconsistent

a b c d g

m e f

k i h jCut 1 Cut 2

A cut is a set of events.

(Not consistent)(Consistent)

P1

P2

P3

time

Page 20: Token-passing Algorithms for mutual exclusion

Consistent snapshot

The set of states immediately following the events (actions) in a consistent cut forms a consistent snapshot of a distributed system.

• A snapshot that is of practical interest is the most recent one. Let C1 and C2 be two consistent cuts and C1 C2. Then C2 is more recent than C1.

• Analyze why certain cuts in the one-dollar bank are inconsistent.

Page 21: Token-passing Algorithms for mutual exclusion

Consistent snapshot

How to record a consistent snapshot? Note that

1. The recording must be non-invasive.

2. Recording must be done on-the-fly.

You cannot stop the system.