Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 42

Subject Name :- DISTRIBUTED SYSTEMS

Subject Code :- RCS-701


Unit No. :- 2
Lecture No. :- 2 (PPT-1)
Topic Name :- TOKEN BASED MUTUAL
EXCLUSION ALGORITHM

SHREYI MITTAL
DEPARTMENT Of COMPUTER SCIENCE
8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 1
CONTENT
• Classification of Mutual Exclusion Algorithms
• Introduction
• Token based Algorithms
• Classification on basis of Approach
• Performance Analysis

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 2


MUTUAL EXCLUSION ALGORITHMS

• The mutual exclusion algorithms can be broadly


classified into two categories.
(A) Shared memory based algorithms
• The distributed shared memory is an abstraction
used for sharing data between computers that do
not share physical memory.
• These algorithms access and update some
common variables for solving mutual exclusion
problem.
8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 3
(B) Message passing based
algorithms
• In message passing system, processes can
communicate with each other only by
exchanging messages over a communication
network.
• The message passing algorithms can be further
classified into two categories:
1. Non-Token Based Algorithms
2. Token Based Algorithms
8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 4
TOKEN BASED
ALGORITHMS
• A privilege message(token) is shared among
all the processes in the system. A process can
enter CS, only if it is in possession of the
privilege message.
• A process wishing to enter CS sends its
request to a set of processes called its request
set and waits for the token.
• The token based algorithms generally use
sequence numbers to distinguish between old
requests and current request made by the same
8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 5
TOKEN BASED
ALGORITHMS
• Token based algorithms produce less message
traffic in comparison to non-token based
algorithms.
• Because of the existence of a unique token in
the system, token based algorithms are
deadlock free. But their resiliency to failure is
poor, because if the process having token fails
or token is lost in transit, a complex process of
token regeneration and recovery has to be
8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 6
CLASSIFICATION of
ALGORITHMS
• Token based algorithms for mutual exclusion
can be classified in to following categories:
(i) Broad cast based algorithms
(ii) Logical structure based algorithms
(iii)Centralized token based algorithms

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 7


BROAD CAST
BASED ALGORITHMS

• In broadcast based algorithms, a site requesting to


enter CS sends a request message to the sites in
its request set in parallel and waits for the
privilege message.
• Upon receiving the privilege message, the site
can enter CS.
• Eg: Suzuki–Kasami algorithm, Singhal’s
Heuristic
8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 8
SUZUKI KASAMI
• A unique token is shared among all sites. A site can
proceed to its CS if it possesses the token.
DATA STRUCTURE
• A REQUEST message of site Sj has the form
REQUEST(j, n), where n is a sequence number that
indicates that site Sj is requesting its nth CS execution.
Each site Si maintains an array of integers RNi[1..
n]where RNi [j] records the largest sequence number
received so far in a REQUEST message from Sj.

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 9


DATA STRUCTURE
• A REQUEST MESSAGE(j, n) received by Si is
outdated if RNi[j]>n.
• Upon receiving REQUEST(j, n), site Si updates
RNi by setting RNi[j]:= MAX (RNi[j],n).
• The token is associated with an array of integers
LN[1.. N ] . 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.

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 10


DATA STRUCTURE
• The token array LN enables site Si exiting its
CS to determine if some other site has an
outstanding request.
• All sites Sj such that Rni[j]=LN[j]+1 are waiting
to execute their latest request of CS, and will be
placed in the token queue Q. Site Si then sends
the token to the site at the head of Q.

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 11


ALGORITHM

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 12


8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 13
ANALYSIS
• The main design issues in this algorithm are:
1. Distinguishing outdated REQUEST messages from
current ones.
2. Determining which site has an outstanding request
for the CS.
• Performance: Suzuki-Kasami algorithm requires 0
to N messages per CS invocation. Synchronization
delay in the algorithm is 0 or T . No message is
needed and the synchronization delay is 0 if the site
holds the token at the time of its request.

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 14


8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 15
8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 16
SINGHAL’S HUERISTIC
• Instead of broadcasting request messages for
acquiring the token, Singhal’s algorithm has each
site keep information about the state of other sites
and use the information to select the sites that are
likely to have the token.
• The objective of this effort is to reduce the number
of messages required for the CS execution. It is
called a heuristic algorithm because sites are
heuristically selected for sending the request
messages.
8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 17
DATA STRUCTURE
• In order to avoid the request being
unanswered, a requesting site must send the
request message to a site that either holds the
token or is going to obtain the token in the
near future.
• Hence one design requirement of this
algorithm is that a site must select a subset of
sites such that at least one of those sites is
guaranteed to get the token in the near future.
8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 18
DATA STRUCTURE

• A site Si maintains two arrays SVi [1…N} and


SNi [1…N ], to store information about other
sites in the system.
• These arrays store the state and the highest
known sequence number for each site,
respectively.
• The token also contain two similar arrays,
denoted by TSV[1..N ] and TSN[1..N ] .
8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 19
8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 20
DATA STRUCTURE

• A site can be in one of the following states:

1. R – requesting the CS
2. E – executing the CS
3. H – holding the idle token
4. N – none of the above

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 21


ALGORITHM

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 22


8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 23
ANALYSIS
• Singhal’s algorithm allows a site to enter CS without
communicating with every site in the system.
• In low to moderate loads, the message traffic is N/2
because a site needs to send REQUEST to
approximately half the sites on average.
• At high loads, however, when every site is requesting
for CS, then most entries in every site’s SV array have
the value R, hence the message traffic increases to N.
• Synchronization delay in the algorithm is T .

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 24


LOGICAL STRUCTURE
BASED ALGORITHMS
• The logical structure based algorithms impose
a logical structure (such as tree) on the sites of
the system.
• The request of a site wishing to enter CS
follows a path between requesting site and the
site holding token.
• The token also follows the path from the site
holding the token to the requesting site.

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 25


LOGICAL STRUCTURE
BASED ALGORITHMS

• The logical structure based algorithms have an


average lower message cost as compared to
broad cast based algorithms, presents better
scalability, and uses simple data structures.
• However logical structure based algorithms
are very sensitive to site failure, because these
can not tolerate with a single failure in the
token request path.

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 26


RAYMOND’S TREE
BASED ALGORITHM
• In Raymond’s tree-based distributed mutual
exclusion algorithm, all the messages are sent
along the undirected edges of this tree.
• There is a privilege message and the site having
privilege message is allowed to enter its CS.
• Each site maintains a variable holder, which
indicates the location of the privilege message
relative to the node.

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 27


RAYMOND’S TREE
BASED ALGORITHM
STATIC APPROACH DYNAMIC APPROACH
• It assumes that the sites in • In this algorithm every
the system being arranged process maintains two
in an unrooted tree pointers father and next.
structure. In it all the • The father indicates the
messages are sent along process to which the
the undirected edges of request for CS access
this tree. should be forwarded and
• It makes the algorithm the next indicates the
highly dependent on the node to which access
topology of the tree. permission should be
8/8/2020 forwarded.
DISTRIBUTED SYSTEM- UNIT: 2 28
DATA STRUCTURE
• Every site maintains a local variable holder that
points to its parent site in the tree structure.
• At the root site, holder points to itself.
• Every site also keeps a FIFO queue, called
REQUEST_QUEUE, which stores the requests
of those sites that have sent a request to this
site, but have not yet been sent the token.

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 29


8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 30
8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 31
8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 32
8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 33
ANALYSIS
• The algorithm is free from deadlock because the
acyclic nature of the structure eliminates the possibility
of circular wait among requesting sites.
• The algorithm is free from starvation can be
rationalized based on two facts:
(1) A site serves requests from its REQUEST_QUEUE in
the FCFS order, and
(2) Every site has a path leading to the site that has the
token.

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 34


PERFORMANCE
• The average performance of Raymond’s
algorithm O(log N) messages per CS
invocation because the average distance
between any two nodes in a tree with N nodes
is O(log N) .
• Synchronization delay in the algorithm is
=( T logN )/2.

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 35


CENTRALIZED TOKEN
BASED ALGORITHMS
• Centralized algorithms are those, in which
there is a central coordinator node.
• Every requesting node requires the permission
of the central coordinator to execute its CS.
• Number of messages required in centralized
algorithms is very low as compared to other
techniques.

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 36


CENTRALIZED TOKEN
BASED ALGORITHMS
• However, in centralized algorithms central
coordinator is generally overloaded and becomes
the performance bottleneck.
• There is a single point of failure in these algorithms;
if central coordinator fails, whole system will fail.
• Another disadvantage of central algorithms is that
two sequential messages (release and privilege) are
required to pass the lock from one process to
another.

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 37


8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 38
PERFORMANCE
ANALYSIS

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 39


QUESTIONS
Q1. Mutual Exclusion algorithms are classified
using shared memory and massage passing
approach. Explain?
Q2. What are TOKEN based algorithms. Explain?
Q3. Do a comparative study on Token Based
Algorithms?
Q4. What and how does algorithm ensures Mutual
Exclusion?

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 40


REFERENCE
• Singhal&Shivaratri, "Advanced Concept in
Operating Systems", McGraw Hill.
• https://www.semanticscholar.org/paper/A-
Study-of-Token-Based-Algorithms-for-
Distributed-
Swaroop/d34f91765552fae3be17ec5a5085c9f
e1e838665

8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 41


8/8/2020 DISTRIBUTED SYSTEM- UNIT: 2 42

You might also like