DC - Unit III
DC - Unit III
ENGINEERING
Semester/Year: III/V
Prepared by Approved by
Dr.N.Indumathi HoD
1
UNIT – III : Syllabus
SYLLABUS:
TOTAL TOPICS: 10
2
Mutex is a unit of code that averts contemporaneous access to shared resources.
Mutual exclusion is concurrency control’s property that is installed for the objective of
averting race conditions.
Examples of mutual exclusion are:
locks, recursive locks, RW locks, semaphores, etc.
1.1.1 Examples of Mutual Exclusion
There are many types of mutual exclusion, some of them are mentioned below :
a) Locks :
It is a mechanism that applies restrictions on access to a resource when multiple threads
of execution exist.
b) Recursive lock :
It is a certain type of mutual exclusion (mutex) device that is locked several times by
the very same process/thread, without making a deadlock.
While trying to perform the "lock" operation on any mutex may fail or block when the
mutex is already locked, while on a recursive mutex the operation will be a success only if the
locking thread is the one that already holds the lock.
c) Semaphore :
It is an abstract data type designed to control the way into a shared resource by multiple
threads and prevents critical section problems in a concurrent system such as a multitasking
operating system.
They are a kind of synchronization primitive.
d) Readers writer (RW) lock :
It is a synchronization primitive that works out reader-writer problems. It grants
concurrent access to the read-only processes, and writing processes require exclusive access.
This conveys that multiple threads can read the data in parallel however exclusive lock
is required for writing or making changes in data. It can be used to manipulate access to a data
structure inside the memory.
The status of shared resources and the To eliminate the mutual exclusion
status of users is easily available in the problem in distributed system approach
shared memory so with the help of shared based on message passing is used.
variable A site in distributed system do not have
(For example: Semaphores) mutual complete information of state of the
exclusion problem can be easily solved. system due to lack of shared memory and
a common physical clock.
2. PREMLIMIMARIES
4
The process that is outside the critical section must not interfere with another for access
to the critical section.
The goal is to get a lock on a resource: permission to access the resource exclusively.
When a process is finished using the resource, it releases the lock, allowing another
process to get the lock and access the resource.
2.2 Components of Mutual exclusion Algorithm
The requirements of mutual exclusion describe three major compartments:
i) System model
ii) Requirements that mutual exclusion algorithms
iii) Metrics we use to measure the performance of mutual exclusion algorithms.
i) System model
The system consists of N sites, S1, S2, ..., SN. We assume that a single process is
running on each site.
The process at site Si is denoted by pi.
A process wishing to enter the CS, requests all other or a subset of processes by
sending REQUEST messages, and waits for appropriate replies before entering the
CS.While waiting the process is not allowed to make further requests to enter the CS.
In the ‘requesting the CS’ state, the site is blocked and can not make further
requestsfor the CS. In the ‘idle’ state, the site is executing outside the CS.
In the token-based algorithms, a site can also be in a state where a site holding the
token is executing outside the CS. Such state is referred to as the idle token state.
At any instant, a site may have several pending requests for CS. A site queues up
theserequests and serves them one at a time.
5
Note:
We assume that channels reliably deliver all messages, sites do not crash, and
thenetwork does not get partitioned.
Some mutual exclusion algorithms are designed to handle such situations. Many
algorithms use Lamport-style logical clocks to assign a timestamp to critical section
requests.
Timestamps are used to decide the priority of requests in case the of a conflict.
A general rule followed is that the smaller the timestamp of a request, the
higher itspriority to execute the CS.
We use the following notations:
N denotes the number of processes or sites involved in invoking the criticalsection,
T denotes the average Message Time Delay,
E denotes the average critical section Execution Time.
ii) Requirements of Mutual exclusion Algorithm
Any viable mutual exclusion algorithm must satisfy three properties:
i) No Deadlock: Freedom from deadlocks (desirable)
Two or more site should not endlessly wait for any message that will never
arrive.
ii) No Starvation: Guarantee mutual exclusion (required)
Every site who wants to execute critical section should get an opportunity to
execute it in finite time.
Any site should not wait indefinitely to execute critical section while other site
are repeatedly executing critical section
iii) Fairness:
Each site should get a fair chance to execute critical section.
Any request to execute critical section must be executed in the order they are
made i.e Critical section execution requests should be executed in the order of
their arrival in the system.
iv) Fault Tolerance:
In case of failure, it should be able to recognize it by itself in order to continue
functioning without any disruption.
6
Some points are need to be taken in consideration to understand mutual exclusion fully
:
For example, directory management where updates and reads to a directory must be
done atomically to ensure correctness.
3) Mutual exclusion for a single computer is not applicable for the shared resources since it
involves resource distribution, transmission delays, and lack of global information.
Necessary Conditions for Mutual Exclusion
There are four conditions applied to mutual exclusion, which are mentioned below :
7
c. Response time: It is the time interval a request waits for its CS execution to be
over after its request messages have been sent out (see Figure 9.2).
d. System throughput: It is the rate at which the system executes requests for the
CS. If SD isthe synchronization delay and E is the average critical section execution
time, then the throughput is given by the following equation:
System Throughput=1/(SD+E)
Generally, the value of a performance metric fluctuates statistically from request to
request and we generally consider the average value of such a metric.
8
Low and High Load Performance: The load is determined by the arrival rate of
CS execution requests. Two special loading conditions, viz., “low load" and “high
load".
Under low load conditions, there is seldom more than one request for the
criticalsection present in the system simultaneously.
Under heavy load conditions, there is always a pending request for criticalsection ata site.
As we know shared variables or a local kernel can not be used to implement mutual
exclusion in distributed systems.
Message passing is a way to implement mutual exclusion.
9
Types of mutual exclusion algorithms:-
a) Centralized Algorithm
b) Distributed Algorithm
a) Centralized Algorithm :-
As its name implies, there is single coordinator which handles all the requests to access
the shared data.
Every process takes permission to the coordinator, if coordinator agree and will give
permission then a particular process can enter into CS.
Coordinator will maintain a queue and keep all the requests in order.
Benefits
i) It is Fair algorithm; it follow FIFO algorithm concept for giving permission.
ii) It is very simple algorithm in context of implementation.
iii) We can use this scheme for general resource allocation. Shortcomings
iv) No multiple point failures, No fault tolerant.
v) Uncertainty between No-reply and permission denied.
vi) Performance bottleneck because of single coordinator in a large system.
b) Distributed algorithm :-
In distributed algorithm , there is no coordinator.
For permission to enter into CS, Every process communicates to other process.
These algorithms are sectioned into two parts –
i) Non-Token based algorithms
ii) Token based algorithms
Contention (Non-Token) based algorithms :-
In this algorithm, process converse with a group of other process to select who should execute
the critical section first.
These algorithms also divided into 2 parts:
1. Timestamp based
2. Voting scheme
Controlled (TOKEN) BASED ALGORITHMS :
Token-based algorithms are the algorithm in which a site is allowed to enter its CS if
it possesses the token.
This token is unique among the processes.
10
Instead of timestamps Token based algorithms use sequence numbers to differentiate
between old and existing requests.
Usually FIFO message delivery is not adopted.
Below are the three approaches based on message passing to implement mutual exclusion
in distributed systems:
a) Token Based Algorithm
b) Non-token based approach
c) c) Quorum based approach
a) Token Based Algorithm
A unique token is shared among all the sites.
The central server algorithm simulates a single processor system.
One process in the distributed system is elected as the coordinator.
When a process wants to enter a resource, it sends a request message identifying the
resource, if there are more than one, to the coordinator.
If a site possesses the unique token, it is allowed to enter its critical section.
If nobody is currently in the section, the coordinator sends back a grant message
(Figure 1b) and marks that process as using the resource.
If, however, another process has previously claimed the resource, the server simply
does not reply, so the requesting process is blocked.
The coordinator keeps state on which process is currently granted the resource and a
which processes are requesting the resource.
Token-based algorithm handle the failure of a site that possesses the token in this
way:
If a site that possesses the token fails, then
o the token is lost until the site recovers or another site generates a new token.
In the meantime, no site can enter the critical section.
This approach uses sequence number to order requests for the critical section.
Each requests for critical section contains a sequence number. This sequence number is
used to distinguish old and current requests.
This approach insures Mutual exclusion as the token is unique
11
Two basic Timestamp-based Contention algorithms are:
a) LAMPORT’S ALGORITHM :
Lamport designed a distributed MUTEX algorithm on the basis of his concept of logical
clock .
This is a algorithm which is a non-token based scheme.
Non-token based protocols use timestamps to order requests for CS.
b) RICART-AGRAWALA ALGORITHM:
Ricart-agrawala algorithm is an expansion and optimization of Lamport’s protocol.
This algorithm is also for MUTEX and it is a non-token based algorithm.
This algorithm combines the RELEASE and REPLY message of lamport’s algorithm
and decreases the complexity of the algorithm by (N-1).
b) Non-token based approach
A site communicates with other sites in order to determine which sites should execute
critical section next. This requires exchange of two or more successive round of messages
among sites.
This approach use timestamps instead of sequence number to order requests for the
critical section.
Whenever a site make request for critical section, it gets a timestamp.
Timestamp is also used to resolve any conflict between critical section
requests.
The non-token-based approach ensure fairness among the sites
The non-token-based approach uses a logical clock to order requests for the critical
section.
Each site maintains its own logical clock, which gets updated with each message it
sends or receives.
This ensures that requests are executed in the order they arrive in the system, and that
no site is unfairly prioritized.
All algorithm which follows non-token based approach maintains a logical clock.
Logical clocks get updated according to Lamport’s scheme
Example : Ricart–Agrawala Algorithm
c) Quorum based approach
12
A quorum is a subset of sites that a site requests permission from to enter the critical
section.
The quorum is determined based on the size and number of overlapping subsets
among the sites.
Instead of requesting permission to execute the critical section from all other sites,
Each site requests only a subset of sites which is called a quorum.
Any two subsets of sites or Quorum contains a common site.
This common site is responsible to ensure mutual exclusion
Example : Maekawa’s Algorithm
Difference between Token based and Non-Token based Algorithms in Distributed
System:
The token-based algorithm uses the Non-Token based algorithm uses the
sequences to order the request for the timestamp (another concept) to order
Critical Section and to resolve the conflict the request for the Critical Section and
for the simultaneous requests for the to resolve the conflict for the
3. System. simultaneous requests for the System.
13
S.No. Token Based Algorithms Non-Token Based Algorithms
Here the access control is quite Fine- Here the access control is not so fine as
grained because here inside the token there is no token which can specify
roles, permissions and resources can be roles, permission, and resources for the
8. easily specifying for the user. user.
14
3. LAMPORT’S ALGORITHM
The algorithm of Lamport timestamps is a simple algorithm used to determine the order
of events in a distributed computer system.
As different nodes or processes will typically not be perfectly synchronized, this
algorithm is used to provide a partial ordering of events with minimal overhead, and
conceptually provide a starting point for the more advanced vector clock method.
2. If two events, a and b, occur in different processes which not at all exchange messages
amongst them, then a→→b is not true, but neither is b→→a which is
antisymmetry.
15
Lamport’s Distributed Mutual Exclusion Algorithm is a permission based
algorithm proposed by Lamport as an illustration of his synchronization scheme for
distributed systems.
In permission based timestamp is used to order critical section requests and to resolve
any conflict between requests.
In Lamport’s Algorithm critical section requests are executed in the increasing order
of timestamps i.e a request with smaller timestamp will be given permission to
execute critical section first than a request with larger timestamp.
3.2 Basic messaging mecanisms in Mutual exclusion algorithms:
Three type of messages ( REQUEST, REPLY and RELEASE) are used and
communication channels are assumed to follow FIFO order.
A site send a REQUEST message to all other site to get their permission to enter
critical section.
A site send a REPLY message to requesting site to give its permission to enter the
critical section.
A site send a RELEASE message to all other site upon exiting the critical section.
Every site Si, keeps a queue to store critical section requests ordered by their
timestamps. request_queuei denotes the queue of site Si
A timestamp is given to each critical section request using Lamport’s logical clock.
16
Timestamp is used to determine priority of critical section requests. Smaller timestamp
gets high priority over larger timestamp. The execution of critical section request is
always in the order of their timestamp.
3.3 Lamport Algorithm:
17
o Lamport's logical clocks can be used to implement totally-ordered multicast in a
completely distributed fashion
o Lamport's logical clocks can be used to implement totally-ordered multicast in a
completely distributed fashion
1. Causality
Lamport's logical clocks: If A →→ B then L(A) < L(B), Reverse is not true. Nothing
can be said about events by comparing timestamps.
Need to capture causality: If A →→ B then A causally precedes B. Need a
timestamping mechanism such that: T(A) < T(B) if A causally precedes B
18
3.4 Timestamp in Lamport clocks
(1) at the sender, we have the event of sending the message and
19
The clock is a process-wide counter (e.g., a global variable) and is always incremented
before each event.
o When a message arrives, if the receiver’s clock is less than or equal to the
message’s timestamp, the clock is set to the message timestamp + 1.
This ensures that the timestamp marking the event of a received message will always be
greater than the timestamp of that sent message.
3. 5 Lamport Clocks
20
There are three conditions in which we can say an event a happens before b:
Lamport clocks tag events in a distributed system and order them accordingly.
We seek a clock time C(a) for every event a.
The clock condition is defined as follows:
Before the execution of an event, the local clock is updated. This can be explained by
the equation Ci = Ci+1, where i is the process identifier.
21
When a message is sent to another process, the message contains the process’ local
clock, Cm.
When a process receives a message m, it sets its local clock to 1+max(CI, Cm).
The following diagram illustrates how the Lamport clock algorithm works:
In the example above, all local clocks start from a value of 0. Before the execution of an
event, the local clock increments by 1.
Notice that P2’s clock starts from 0, but on the arrival of the message m1 from P1, it
updates its clock in accordance with the third rule mentioned above, i.e., 1+max(Ci, Cm)
where Ci = 0 and Cm = 2.
Hence, P2’s final clock value is 3.
22
Clock Assignment
This simple incrementing counter does not give us results that are consistent with causal
events. If event a happened before event b then we expect clock(a) < clock(b).
If an event is the sending of a message then the timestamp of that event is sent along with the
message. If an event is the receipt of a message then the the algorithm instructs you to compare
the current value of the process' timestamp counter (which was just incremented before this
event) with the timestamp in the received message.
If the timestamp of the received message is greater than or equal to that of the event, the event
and the process' timestamp counter are both updated with the value of the timestamp in the
received message plus one.
This ensures that the timestamp of the received event and all further timestamps on that
process will be greater than that of the timestamp of the event of sending the message as well
as all previous messages on that process.
In the figure below, event i in process P1 is the receipt of the message sent by event b in
P0. If event i was just a normal local event, the P1 would assign it a timestamp of 2.
However, since the received timestamp is 2, which is greater than or equal to 2, the
timestamp counter is set to 2+1, or 3.
23
Event i gets the timestamp of 3. This preserves the relationship b→i, that is, b happened
before i.
A local event after i would get a timestamp of 4 because the process P1’s counter was
set to 3 when the timestamp for i was adjusted.
Event c in process P0 is the receipt of the message sent at event h. Here, the timestamp
of c does not need to be adjusted.
The timestamp in the message is 1, which is less than the event timestamp of 3 that P0 is
ready to assign to c.
If event j was a local event, it would get the next higher timestamp on P1: 4.
However, it is the receipt of a message that contains a timestamp of 6, which is greater
than or equal to 4, so the event gets tagged with a timestamp of 6+1 = 7.
With Lamport timestamps, we are assured that two causally-related events will have
timestamps that reflect the order of events.
For example, event h happened before event m in the Lamport causal
sense.
The chain of causal events is h→c, c→d, and d→m.
Since the happened-before relationship is transitive, we know
that h→m (h happened before m).
Lamport timestamps reflect this.
The timestamp for h (1) is less than the timestamp for m (7).
24
However, just by looking at timestamps we cannot conclude that there is a causal
happened-before relation.
For instance, because the timestamp for k (1) is less than the timestamp for i (3) does
not mean that k happened before i.
Those events happen to be concurrent but we cannot discern that by looking at Lamport
timestamps.
We need need to employ a different technique to be able to make that determination.
That technique is the use of vector timestamps.
One result of Lamport timestamps is that multiple events on different processes may all
be tagged with the same timestamp.
We can force each timestamp to be unique by suffixing it with a globally unique
process number.
While these new timestamps will not relate to real time ordering, each will be a unique
number that can be used for consistent comparisons of timestamps among multiple
processes (e.g., if we need to make a decision on who gets to access a resource based on
comparing two timestamps).
A second deficiency with Lamport timestamps is that, by looking at timestamps, one
cannot determine whether there is a causal relationship between two events.
For example, just because event a has a timestamp of 5 and event b has a timestamp of
6, it does not imply that event a happened before event b.
4. RICART-AGRAWALA ALGORITHM
25
Two type of messages ( REQUEST and REPLY) are used and communication
channels are assumed to follow FIFO order.
A site send a REQUEST message to all other site to get their permission to
enter the critical section.
A site send a REPLY message to another site to give its permission to enter the
critical section.
A timestamp is given to each critical section request using Lamport’s logical
clock.
Timestamp is used to determine priority of critical section requests. Smaller
timestamp gets high priority over larger timestamp.
The execution of critical section request is always in the order of their
timestamp.
Algorithm:
26
Advantages of the Ricart-Agrawala Algorithm:
i) Low message complexity: The algorithm has a low message complexity as it requires
only (N-1) messages to enter the critical section, where N is the total number of nodes
in the system.
ii) Scalability: The algorithm is scalable and can be used in systems with a large number
of nodes.
iii) Non-blocking: The algorithm is non-blocking, which means that a node can continue
executing its normal operations while waiting to enter the critical section.
Drawbacks of Ricart–Agrawala algorithm:
i) Unreliable approach:
Failure of any one of node in the system can halt the progress of the system. In
this situation, the process will starve forever.
The problem of failure of node can be solved by detecting failure after some
timeout.
ii) Performance:
Synchronization delay is equal to maximum message transmission time
It requires 2(N – 1) messages per Critical section execution
What is the difference between Lamport algorithm and Ricart-Agrawala algorithm?
Both the Ricart & Agrawala and Lamport algorithms are contention-based algorithms.
With Lamport's algorithm, everyone immediately responds to a mutual exclusion
request message whereas with the Ricart & Agrawala, a process that is using the
resource will delay its response until it is done.
5. SUZUKI – KASAMI ALGORITHM
Non-token based algorithms uses timestamp to order requests for the critical section
where as sequence number is used in token based algorithms.
When a site Si wants to enter the critical section and it does not have the token then it
increments its sequence number RNi[i] and sends a request message REQUEST(i,
sn) to all other sites in order to request the token.
Here sn is update value of RNi[i]
When a site Sj receives the request message REQUEST(i, sn) from site Si, it
sets RNj[i] to maximum of RNj[i] and sn i.e RNj[i] = max(RNj[i], sn).
After updating RNj[i], Site Sj sends the token to site Si if it has token
and RNj[i] = LN[i] + 1
28
To execute the critical section:
Site Si executes the critical section if it has acquired the token.
To release the critical section:
After finishing the execution Site Si exits the critical section and does following:
sets LN[i] = RNi[i] to indicate that its critical section request RNi[i] has been
executed
For every site Sj, whose ID is not present in the token queue Q, it appends its ID
to Q if RNi[j] = LN[j] + 1 to indicate that site Sj has an outstanding request.
After above updation, if the Queue Q is non-empty, it pops a site ID from the Q and
sends the token to site indicated by popped ID.
If the queue Q is empty, it keeps the token
Message Complexity:
The algorithm requires 0 message invocation if the site already holds the idle token at
the time of critical section request or maximum of N message per critical section
execution.
This N messages involves
(N – 1) request messages
1 reply message
Drawbacks of Suzuki–Kasami Algorithm:
Non-symmetric Algorithm: A site retains the token even if it does not have requested for
critical section. According to definition of symmetric algorithm
“No site possesses the right to access its critical section when it has not been requested.”
Performance:
Synchronization delay is 0 and no message is needed if the site holds the idle token at the
time of its request.
In case site does not holds the idle token, the maximum synchronization delay is equal to
maximum message transmission time and a maximum of N message is required per critical
section invocation.
29
6. DEADLOCK
ii) Prevention: Constraints are imposed on the ways in which processes request resources in
order to prevent deadlocks.
iii) Detection and recovery: Deadlocks are allowed to occur and a detection algorithm is used
to detect them. After a deadlock is detected, it is resolved by certain means.
i) Resource Deadlock: A resource deadlock occurs when two or more processes wait
permanently for resources held by each other.
A process that requires certain resources for its execution, and cannot proceed until it has
acquired all those resources.
It will only proceed to its execution when it has acquired all required resources.
It can also be represented using AND condition as the process will execute only if it has all the
required resources.
30
ii) Communication Deadlock:
On the other hand, a communication deadlock occurs among a set of processes when
they are blocked waiting for messages from other processes in the set in order to start
execution but there are no messages in transit between them.
When there are no messages in transit between any pair of processes in the set, none of
the processes will ever receive a message.
This implies that all processes in the set are deadlocked. Communication deadlocks can
be easily modeled by using WFGs to indicate which processes are waiting to receive
messages from which other processes.
Hence, the detection of communication deadlocks can be done in the same manner as
that for systems having only one unit of each resource type.
7. System Model
31
A process can be in two states:
i) running or
ii) blocked
In the running state (also called active state), a process has all the needed resources and
is either executing or is ready for execution.
In the blocked state, a process is waiting to acquire some resource.
Wait-For-Graph (WFG)
The state of the system can be modeled by directed graph, called a wait for graph
(WFG). In a WFG , nodes are processes and there is a directed edge from node P1 to
mode P2 if P1 is blocked and is waiting for P2 to release some resource.
A system is deadlocked if and only if there exists a directed cycle or knot in the WFG.
Figure 1 shows a WFG, where process P11 of site 1 has an edge to process P21 of site 1
and P32 of site 2 is waiting for a resource which is currently held by process P21.
At the same time process P32 is waiting on process P33 to release a resource.
If P21 is waiting on process P11, then processes P11, P32 and P21 form a cycle and all
the four processes are involved in a deadlock depending upon the request model.
32
8. PRELIMINARIES
Deadlock handling using the approach of deadlock detection entails addressing two basic
issues: First, detection of existing deadlocks and second resolution of detected deadlocks.
33
Correctness Criteria:
The algorithm should not report deadlocks which do not exist (called phantom or false
deadlocks).
9. MODELS OF DEADLOCKS
34
9.1 Single Resource Model
A process can have at most one outstanding request for only one unit of a resource.
The maximum out-degree of a node in a WFG for the single resource model can be 1, the
presence of a cycle in the WFG shall indicate that there is a deadlock.
In the AND model, a process can request for more than one resource simultaneously and the
request is satisfied only after all the requested resources are granted to the process. The out
degree of a node in the WFG for AND model can be more than 1.
The presence of a cycle in the WFG indicates a deadlock in the AND model.
Since in the single-resource model, a process can have at most one outstanding request, the
AND model is more general than the single-resource model.
AND Model
In the AND model, a passive process becomes active (i.e., its activation condition is
fulfilled) only after a message from each process in its dependent set has arrived.
In the AND model, a process can request more than one resource simultaneously and the
request is satisfied only after all the requested resources are granted to the process.
The out degree of a node in the WFG for AND model can be more than 1.
35
The presence of a cycle in the WFG indicates a deadlock in the AND model.
In the AND model, if a cycle is detected in the WFG, it implies a deadlock but not vice
versa. That is, a process may not be a part of a cycle, it can still be deadlocked.
A process can make a request for numerous resources simultaneously and the request is
satisfied if any one of the requested resources is granted.
Presence of a cycle in the WFG of an OR model does not imply a deadlock in the OR model.
36
If all nodes are OR nodes, then process P11 is not deadlocked because once process P33
releases its resources, P32 shall become active as one of its requests is satisfied.
After P32 finishes execution and releases its resources, process P11 can continue with
its processing. In the OR model, the presence of a knot indicates a deadlock
Deadlock in OR model:
With every blocked process, there is an associated set of processes called dependent set.
A process shall move from an idle to an active state on receiving a grant message from any
of the processes in its dependent set.
A process is permanently blocked if it never receives a grant message from any of the
Processes in its dependent set.
In short, a processis deadlocked or permanently blocked, if the following conditions are met:
A blocked process P is the set S becomes active only after receiving a grant message from a
process in its dependent set, which is a subset of S.
37
The AND-OR Model
A generalization of the previous two models (OR model and AND model) is the AND-
OR model.
In the AND-OR model, a request may specify any combination of and and or in the
resource request.
For example, in the AND-OR model, a request for multiple resources can be of the
form x and (y or z).
To detect the presence of deadlocks in such a model, there is no familiar construct of
graph theory using WFG.
Since a deadlock is a stable property, a deadlock in the AND-OR model can be detected
by repeated application of the test for OR-model deadlock.
The (p q) Model
The (p q) model (called the P-out-of-Q model) allows a request to obtain any k
available resources from a pool of n resources.
It has the same in expressive power as the AND-OR model.
However, (p q) model lends itself to a much more compact formation of a request.
Every request in the (p q) model can be expressed in the AND-OR model and vice-
versa. Note that AND requests for p resources can be stated as (p p) and OR requests for
p resources can be stated as (p 1).
Unrestricted Model
In the unrestricted model, no assumptions are made regarding the underlying structure of
resource requests.
Only one assumption that the deadlock is stable is made and hence it is the most general
model.
Concerns about properties of the problem (stability and deadlock) are separated from
underlying distributed systems computations (e.g., message passing versus synchronous
communication).
38
The Chandy–Misra–Haas algorithm resource model checks for deadlock in
a distributed system.
It was developed by K. Mani Chandy, Jayadev Misra and Laura M Haas.
Chandy-Misra-Haas’s Distributed Deadlock Detection Algorithm is an edge chasing
algorithm to detect deadlock in distributed systems.
In edge chasing algorithm, a special message called probe is used in deadlock detection.
A probe is a triplet (i, j, k) which denotes that process Pi has initiated the deadlock
detection and the message is being sent by the home site of process Pj to the home site
of process Pk.
The probe message circulates along the edges of WFG to detect a cycle.
When a blocked process receives the probe message, it forwards the probe message
along its outgoing edges in WFG.
A process Pi declares the deadlock if probe messages initiated by process Pi returns to
itself.
Locally dependent
Consider the n processes P1, P2, P3, P4, P5,, ... ,Pn which are performed in a single
system (controller).
P1 is locally dependent on Pn, if P1 depends on P2, P2 on P3, so on and Pn−1 on Pn.
That is, if {\displaystyle P_{1}\rightarrow P_{2}\rightarrow P_{3}\rightarrow \ldots
on {\displaystyle P_{n}} .
If P1 is said to be locally dependent to itself if it is locally dependent
on Pn and Pn depends on P1:
i.e. if {\displaystyle P_{1}\rightarrow P_{2}\rightarrow P_{3}\rightarrow \ldots
39
Description
The algorithm uses a message called probe(i,j,k) to transfer a message from controller
of process Pj to controller of process Pk.
It specifies a message started by process Pi to find whether a deadlock has occurred or
not. Every process Pj maintains a boolean array dependent which contains the
information about the processes that depend on it.
Initially the values of each array are all "false".
Before sending, the probe checks whether Pj is locally dependent on itself. If so, a
deadlock occurs.
Otherwise it checks whether Pj, and Pk are in different controllers, are locally dependent
and Pj is waiting for the resource that is locked by Pk.
Once all the conditions are satisfied it sends the probe.
On the receiving side, the controller checks whether Pk is performing a task. If so, it
neglects the probe.
Otherwise, it checks the responses given Pk to Pj and dependentk(i) is false.
Once it is verified, it assigns true to dependentk(i).
Then it checks whether k is equal to i. If both are equal, a deadlock occurs, otherwise it
sends the probe to next dependent process.
Algorithm
if
then begin
"dependents""k"(i) = true;
if k == i
end
Example
40
occurrence of deadlock in distributed system
P1 initiates deadlock detection. C1 sends the probe saying P2 depends on P3. Once the
message is received by C2, it checks whether P3 is idle. P3 is idle because it is locally
dependent on P4 and updates dependent3(2) to True.
As above, C2 sends probe to C3 and C3 sends probe to C1. At C1, P1 is idle so it
update dependent1(1) to True. Therefore, deadlock can be declared.
Complexity
Consider that there are "m" controllers and "p" process to perform, to declare whether a
deadlock has occurred or not, the worst case for controllers and processes must be visited.
Therefore, the solution is O(m+p). The time complexity is O(n).
Advantages:
There is no need for special data structure. A probe message, which is very small and
involves only 3 integers and a two dimensional boolean array dependent is used in the
deadlock detection process.
At each site, only a little computation is required and overhead is also low
Unlike other deadlock detection algorithm, there is no need to construct any graph or pass
nor to pass graph information to other sites in this algorithm.
Algorithm does not report any false deadlock (also called phantom deadlock).
Disadvantages:
The main disadvantage of distributed detection algorithms is that all sites may not be
aware of the processes involved in the deadlock which makes resolution difficult. Also,
proof of correction of the algorithm is difficult.
41
It may detect a false deadlock if there is a delay in message passing or if a message is lost.
This can result in unnecessary process termination or resource preemption.
It may not be able to detect all deadlocks in the system, especially if there are hidden
deadlocks or if the system is highly dynamic.
It is complex and difficult to implement correctly. It requires careful coordination between
the processes, and any errors in the implementation can lead to incorrect results.
It may not be scalable to large distributed systems with a large number of processes and
resources. As the size of the system grows, the overhead and complexity of the algorithm
also increase.
10. CHANDY-MISRA-HAAS ALGORITHMS
Data Structures
Each process Pi maintains a boolean array, dependent i, where dependent i(j) is
true only if Pi knows that Pj is dependent on it. Initially, dependent i(j) is
false for all i and j.
42
Therefore, a probe message is continuously circulated along the edges of the global
WFG graph and a deadlock is detected when a probe message returns to its initiating
process.
Performance Analysis
In the algorithm, one probe message (per deadlock detection initiation) is sent on every
edgeof the WFG which that two sites. Thus, the algorithm exchanges at most m(n −
1)/2 messagesto detect a deadlock that involves m processes and that spans over n
sites. The size of messages is fixed and is very small (only 3 integer words). Delay in
detecting a deadlock is O(n).
10.2 CHANDY-MISRA-HAAS ALGORITHM FOR THE OR MODEL
Basic Idea
A blocked process initiates deadlock detection by sending query messages to all processes in
its dependent set (i.e., processes from which it is waiting to receive a message).
When a blocked process Pk receives a query(i, j,k) message, it takes the following actions:
If this is the first query message received by Pk for the deadlock detection initiated by Pi
(called the engaging query), then it propagates the query to all the processes in its
dependent set and sets a local variable numk(i) to the number of query messages sent.
If this is not the engaging query, then Pk returns a reply message to it immediately
provided Pk has been continuously blocked since it received the corresponding engaging
query.
Otherwise, it discards the query. Process Pk maintains a boolean variable waitk(i) that
denotes the fact that it has been continuously blocked since it received the last engaging
query from process Pi.
When a blocked process Pk receives a reply(i, j, k) message, it decrements numk(i) only
if waitk(i) holds. A process sends a reply message in response to an engaging query only
after it has received a reply to every query message it had sent out for this engaging
query. The initiator process detects a deadlock when it receives reply messages to all the
query messages it had sent out.
For ease of presentation, we assumed that only one diffusion computation is initiated for a
process. In practice, several diffusion computations may be initiated for a process (A diffusion
computation is initiated every time the process gets blocked), but, at any time only one
diffusion computation is current for any process. However, messages for outdated diffusion
computations may still be in transit. The current diffusion computation can be distinguished
from outdated ones by using sequence numbers.
Performance Analysis
For every deadlock detection, the algorithm exchanges e query messages and e replymessages,
where e=n(n-1) is the number of edges.