0% found this document useful (0 votes)
19 views64 pages

CS8603 - DS - Unit 3 - Session 1 To 3

Uploaded by

21ad09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views64 pages

CS8603 - DS - Unit 3 - Session 1 To 3

Uploaded by

21ad09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

Unit III

DISTRIBUTED MUTEX & DEADLOCK


Chapter 9 and 10

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Highest
Planned Relevant
DISTRIBUTED MUTEX & DEADLOCK Cognitiv
Hour CO Nos
e level**
Distributed mutual exclusion algorithms: Introduction -
1 CO4 K2
Preliminaries algorithm
CO4
1 Ricart-Agrawala algorithm K2

1 algorithm CO4 K2
1 Suzuki broadcast algorithm CO4 K2
Deadlock detection in distributed systems: Introduction System CO4
1 K2
model Preliminaries
1 Models of deadlocks CO4 K2
1 Algorithms for the single resource model CO4 K2
1 the AND model and CO4 K2
1 the OR model. CO4 K2
DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
Introduction
A mutual exclusive (mutex) is a program object that prevents simultaneous access to a
shared resource.

Mutual exclusion: Concurrent access of processes to a shared resource or data is


executed in mutually exclusive manner.

Only one process is allowed to execute the critical section (CS) at any given time.

In a distributed system, shared variables (semaphores) or a local kernel cannot be used


to implement mutual exclusion.

Message passing is the sole means for implementing distributed mutual exclusion.
DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
Types of Mutual Exclusion

Distributed mutual exclusion algorithms must deal with unpredictable message delays
and incomplete knowledge of the system state.

Three basic approaches for distributed mutual exclusion:

1 Token based approach


2 Non-token based approach
3 Quorum based approach

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Token-based approach

A unique token is shared among the sites.

A site is allowed to enter its CS if it possesses the token.

Mutual exclusion is ensured because the token is unique.

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Non-token based approach

Two or more successive rounds of messages are exchanged among the


sites to determine which site will enter the CS next.

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Quorum based approach:

Each site requests permission to execute the CS from a subset of


sites (called a quorum).

Any two quorums contain a common site.

This common site is responsible to make sure that only one request
executes the CS at any time.

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


System Model

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Requirements of Mutual Exclusion Algorithms

Safety Property: At any instant, only one process can execute the critical section.

Liveness Property: This property states the absence of deadlock and starvation. Two or
more sites should not endlessly wait for messages which will never arrive.

Fairness: Each process gets a fair chance to execute the CS. Fairness property
generally means the CS execution requests are executed in the order of their arrival
(time is determined by a logical clock) in the system

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Performance metrics

Message complexity
number of messages that are required per CS execution by a site

Synchronization delay
After a site leaves the CS, it is the time required and before the next site enters
the CS

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Response time:

The time interval a request waits for its CS execution to be over after its
request messages have been sent out

System throughput: The rate at which the system executes requests for the CS.

system throughput=1/(SD+E)

where SD is the synchronization delay and E is the average critical section


execution time..

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Low and High Load Performance

We often study the performance of mutual exclusion algorithms under two special

The load is determined by the arrival rate of CS execution requests.

Under low load conditions, there is rarely more than one request for the critical
section present in the system simultaneously.

Under heavy load conditions, there is always a pending request for critical section at
a site.

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Algorithm - Intro

Requests for CS are executed in the increasing order of timestamps and time is
determined by logical clocks.

Every site Si keeps a queue, request queuei , which contains mutual exclusion
requests ordered by their timestamps.

This algorithm requires communication channels to deliver messages the FIFO order.

The Lamport algorithm works by passing three messages: REQUEST, REPLY, and
RELEASE

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


The Algorithm
Requesting the critical section

Executing the critical section

Releasing the critical section

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Step 1

P1

P2

P3

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Step 2

P1

P2

P3

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Step 3

P1

P2

P3

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Step 4

P1

P2

P3

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


The Algorithm

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Requesting the critical section

P1

P2

P3

When a site Si wants to enter the CS, it broadcasts a REQUEST(tsi , i ) message to all
other sites
DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
Requesting the critical section

P1

P2

P3

And places the request on request queuei

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Requesting the critical section

P1

P2

P3

When a site Sj receives the REQUEST(tsi , i ) message from site Si ,places site Si
request on request queuej and it returns a timestamped REPLY message to Si .
DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
Executing the critical section
Site Si enters the CS when the following two conditions hold:

P1

P2

P3

L1: Si has received a message with timestamp larger than (ts i , i ) from all other sites.
L2: Si i.
DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
Releasing the critical section

P1

P2

P3

Site Si, upon exiting the CS, removes its request from the top of its request queue and
broadcasts a timestamped RELEASE message to all other sites.
DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
Releasing the critical section

P1

P2

P3

When a site Sj receives a RELEASE message from site Si, it removes Si


its request queue.
DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
Performance

For each CS execution, algorithm requires


( REQUEST messages,
(
( .

Thus, algorithm requires messages per CS invocation.

Synchronization delay in the algorithm is T.

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE 29
Theorem 9.1
exclusion.

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Theorem 9.2 algorithm is fair.

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Ricart and Idea [1981]

Basic idea:
Processes that require entry to a CS multicast a request message

Processes can enter the CS only when all the other processes have replied to this
message

Node pj does not need to send a REPLY to node pi if pj has a request with timestamp
lower than the request of pi (since pi cannot enter before pj anyway in this case)

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Ricart and Idea [1981]

The Ricart-Agrawala algorithm assumes the communication channels are FIFO. The
algorithm uses two types of messages: REQUEST and REPLY.

A process sends a REQUEST message to all other processes to request their


permission to enter the critical section. A process sends a REPLY message to a
process to give its permission to that process.

Processes use Lamport-style logical clocks to assign a timestamp to critical section


requests and timestamps are used to decide the priority of requests.

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Each process pi maintains the Request-Deferred array, RDi , the size of which is the
same as the number of processes in the system.

Initially,

i j : RDi [j]=0.

Whenever pi defer the request sent by pj , it sets RDi [j]=1 and after it has sent a
REPLY message to pj , it sets RDi [j]=0.

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Requesting the critical section

P1

P2

P3

When a site Si wants to enter the CS, it broadcasts a timestamped REQUEST(tsi , i )


message to all other sites
DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
Requesting the critical section

P1

P2

P3

And places the request on request queuei

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Requesting the critical section

When site Sj receives a REQUEST message from site Si , it sends a REPLY message
to site Si if site Sj is neither requesting nor executing the CS, or if the site Sj is
requesting and Si is smaller than site Sj
timestamp.

Otherwise, the reply is deferred and Sj sets RDj [i]=1

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Requesting the critical section

P1

P2

P3

The reply is deferred and Sj sets RDj [i]=1

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Executing the critical section

P1

P2

P3

Site Si enters the CS after it has received a REPLY message from every site it sent a
REQUEST message to.
DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
Releasing the critical section

P1

P2

P3

When site Si exits the CS, it sends all the deferred REPLY messages: j if RDi [j]=1, then
send a REPLY message to Sj and set RDi [j]=0.
DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
Releasing the critical section

P1

P2

P3

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Performance

For each CS execution, Ricart-Agrawala algorithm requires


( 1) REQUEST messages and
(

Thus

Synchronization delay in the algorithm is T.

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE 43
Quorum Based Mutual Exclusion Algorithms

Each site requests only a subset of sites which is called a quorum

A site does not request permission from all other sites, but only from a subset of the
sites.

The request set of sites are chosen such that i j :


1

A site can send out only one REPLY message at any time. A site can send a REPLY
message only after it has received a RELEASE message for the previous REPLY
message.

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


algorithm

algorithm was the first quorum-based


mutual exclusion algorithm. R0 R1

In algorithm, a site does not request


permission from all the sites, but only from a
subset of sites.

With each process i, associate a subset Ri. Divide


the set of processes into subsets R2

The quorums are constructed such as to satisfy the following conditions:

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Condition
Intersection property is a necessary condition for the Si
for all i, j: Ri Rj exclusion requests can be resolved.

Minimality reduces the number of messages to be sent and


for all i: i Ri received by a node.

Equal size means that each node needs to send and receive
for all i: |Ri| = K, for some K the same number of messages to obtain mutual
exclusion (equal work).

Equal effort signifies that each node is equally responsible for


Any site Sj is contained in K number of mutual exclusion (equal responsibility).
Ri i
DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
Maekawa establishes the following relationship between N and K:

Let K = |Ri|. Let each process be a member of D subsets.

If K = D = 3 then N = 7.

When K=D, N = K(K-1)+1.

So ) (from theory of finite projective planes)

Hence K can be found approximated to .


DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
The Algorithm

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
Problem of Deadlocks

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Deadlock Scenario

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Handling Deadlocks

Deadlock handling requires the following three types of messages:

FAILED - indicates that Si cannot grant request because it has currently granted
permission to a site with a higher priority request.

INQUIRE - indicates that Si would like to find out from Sj if it has succeeded in
locking all the sites in its request set.

YIELD - indicates that Si is returning the permission to Sj (to yield to a higher


priority request at Sj ).

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Token based Algorithms

Single token circulates, enter when token is present token is present

Mutual exclusion obvious

Algorithms differ in how to find and get the token

Uses sequence numbers rather than timestamps to differentiate between old and
current requests

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Suzuki Kasami Algorithm

If a site wants to enter the CS and it does not have


the token, it broadcasts a REQUEST message for
the token to all other sites.

A site which possesses the token sends it to the


requesting site upon the receipt of its REQUEST
message.

If a site receives a REQUEST message when it is


executing the CS, it sends the token only after it has
completed the execution of the CS.

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Two Design Issues

How to distinguishing an outdated REQUEST message from a current


REQUEST message

If a site can not determined if the request corresponding to a token request


has been satisfied, it may dispatch the token to a site that does not need it.

How to determine which site has an outstanding request for the CS

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Solution for the first issue

A REQUEST message of site Sj has the form REQUEST(j, n)

A site Si keeps an array of integers RNi [1..N] largest seq number received so far
from site Sj.

Upon receiving the REQUEST(j, n) message, Si sets


RNi [j]:= max(RNi [j], n).
When a site Si receives a REQUEST(j, n) message, the request is outdated if RNi [j]
> n.

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
Solution for the Second issue

The token consists of a queue of requesting sites, Q, and an array of integers


LN[1..N], where LN[j] is the sequence number of the request which site Sj executed
most recently.

After executing its CS, a site Si updates LN[i]:=RNi [i] to indicate that its request
corresponding to sequence number RNi [i] has been executed.

At site Si if RNi [j] = LN[j]+1, then site Sj is currently requesting token.

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


Example of Suzuki-Kasami Algorithm
Execution

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE
The Algorithm

DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE


DR S. PALANIAPPAN, ASSOCIATE PROFESSOR CSE

You might also like