This document discusses various synchronization issues in distributed systems including clock synchronization, event ordering, mutual exclusion, and deadlock. It describes how computer clocks are implemented and different clock synchronization algorithms like centralized and distributed algorithms. It explains logical clocks and happened-before relation for event ordering. Different approaches for mutual exclusion like centralized, distributed, and token-passing are outlined. The four conditions for deadlock and different strategies like avoidance, prevention, and detection and recovery are summarized. Resource allocation graphs and wait-for graphs are introduced for modeling deadlocks.
2. Synchronization issues
Clock synchronization
Event ordering
Mutual exclusion
Deadlock
Election algorithm
Clock synchronization
How computer clocks are implemented
Computer clock consists of three components: a quartz
crystal oscillates at a frequency, a counter register and a
constant register
Constant register stores the frequency of oscillation
Counter register decremented by 1 when it reaches 0 ,
interrupt is generated
Each interrupt is called a clock tick
3. Two types of clock synchronization
1. Synchronization of the computer clocks with real-time
(or external) clocks
Exchange information about the timing of events with other
systems and users
2. Mutual (or internal) synchronization of the clocks of
different nodes of the system
Clock synchronization algorithms
Centralized algorithms
In centralized algorithms one node has a real-time receiver –
called time server node
Two types : passive time server and active time server
Passive time server centralized algorithm
Each node periodically sends a message (“time=?”) to the time
server
Time server quickly responds (“time =T”) when message received
4. When the client node sends “time=?” msg. its
clock time is T0
When it receives the “time =T” msg. its clock time
is T1
Propagation of the msg. “time=T” is (T1-T0)/2
So the client node readjusted with T+ (T1-T0)/2.
Two methods to improve the estimated time
1. Approximate time to process the msg.
“time=?” is known – this time is I – the better
estimation for propagation is (T1-T0-I)/2 –
time is T+ (T1-T0 –I)/2.
2. Several measurement s of T1-T0 are made - T1-
T0 exceeds some threshold is discarded -
average of others with half is added with T.
5. Active time server centralized algorithm
Time server periodically broadcasts its clock time
(“time=T”)
Each node has knowledge of approximate time (Ta)
for propagation of msg. “time=T”
This will be added by node for new time T+Ta
Another algorithm berkeley algorithm
Time server periodically sends (“time=?”) to all
computers
Time server has the prior knowledge of propagation
By this it readjusts the clock values of reply message
Average is taken and readjust this values to all node
and server itself
Two major drawbacks: single point of failure, not
acceptable to get all the time requests services by
single server
6. Distributed Algorithm
Two approaches for internal synchronization
Global Averaging Distributed Algorithm
The clock process at each node broadcasts “resync”
msg. when its local time equals T0+iR
Some integer i, T0 is fixed time agreed upon by all
nodes, R is s system parameter (total no. of nodes, drift
rate, etc)
After broadcasting clock value, clock process node
waits for time T
During this time T it collects “resync” msg. from other
nodes and records the time
At the end of waiting time, clock process finds the
skew time with its own clock
Find fault tolerant average to update clock value
7. Localized Averaging Distributed Algorithms
It is applicable for small networks
Each node exchange its clock time with its neighbors in
the ring, grid or other structure
Then sets the clock time to the average of its own and its
neighbors
Event ordering
Happened-before relation
Satisfies the following conditions
If a and b are events in the same process and a occurs
before b, then ab.
If a is the event of sending a msg. by another process
and b is the event of receipt of the same msg by
another process, then ab.
If ab nad bc, then ac, happenned-before is a
transitive relation
8. Two events a and b are said to be concurrent if they are not
related by happened-before relation
Two event occurs in different processes that do not exchange
msg.either directly or indirectly
The happened-before relation is sometimes also known as the
relation of casual ordering
Logical clocks concept
To associate a timestamp with each system event
Each process pi has a clock Ci, it assign ci(a) to any event a in that
process
The clock is logical clock, implemented by counters
Clock is represented by C, which assigns any event b the number
c(b)
C(b)=cj(b) if b is an event in process pj
For any two events a and b,if ab, then c(a)<c(b)
Implementation of logical clocks
Two conditions satisfied for the relation
C1: if a and b are two events within the same process pi, and a
occurs before b, then ci(a)<ci(b)
C2: if a is sending message by process pi and b is receipt of the
message by process pj, then ci(a)<cj(b)
9. Third condition for the correct functioning of clock,
C3: a clock ci associated with a process pi must always go
forward nor backward
To meet conditions C1, C2, and C3. lamport algorithm
uses following implementation rules
IR1: each process pi increments Ci between any two
successive events
IR2: if event a is the sending of a message m by process
pi, the message m contains a timestamp Tm=Ci(a), upon
receiving m a process pj sents Cj greather than or equal
to its present values but greater than Tm
10. Mutual Exclusion
The sections of a program that need exclusive access to
shared resources are referred to as critical sections
Alogorithms should satisfy the following requirements
1. Mutual exclusion
2. No starvation
Single processor system mutual exclusion implemented
using semaphores, monitors
Three basic approaches for distributed systems are
1. Centralized approach
One of the system is elected as coordinator
It coordinates the entry to the critical sections
Each processor first seek permission for coordinator
If no process is in critical section, permission granted immediately
Two or more process request permission then scheduling
algorithm to be used for granting permission
11. This ensures the mutual exclusion
P1 Pc P3
P2
5- Release
2- Reply
1- Request
9- Release
8- Reply
4- Request
3-Request
6-Reply
7-Release
12. 2. Distributed approach
Decision making distributed across the entire system
When a process wants to enter in CS
It sends message to all other processes
The message contains the following information
1. The process identifier of the process
2. The name of the CS that the process wants to enter
3. A unique timestamp generated by the process for the request
message
On receiving a request message, a process immediately sends back
reply or defers to send based on the following rules
1. If the receiver itself currently in critical section, it simply queues
2. If the receiver is not in CS but is waiting for CS it checks
timestamp of receiver message with its own
1. If senders timestamp is lower, then sends the reply
immediately
2. If receivers timestamp is lower, then it queues senders
request
3. If the receiver is neither is in the CS nor is waiting for its turn,
then immediately sends back a reply message
A process that sends request message that waits for getting reply from
all processes
It enters only if all reply received from other proesses
13. 3. Token-Passing approach
Token is a special type of message
The processes in the system are logically organized in a ring structure
Token is circulated from one process to another around the ring
The algorithm works as follows. When a process receives the token, it checks if it wants
to enter a critical section
1. If it wants to enter a CS, it keeps the token , enters the CS, and exits from CS
releases the token
2. If it does not want to enter a CS, it passes the token
It requires the following types of failures
1. Process failure
o Process failure causes the logical ring to break
o This requires detection of failed process and dynamic reconfiguration of
logical ring
o Detect the neighbor process by sending message and for
acknowledgement
o Process detects its neighbor failed then removes the failed process
o Skipping to process after it
2. Lost token
o If the token is lost, new token must be generated
o One of the process on the ring as a “monitor”
o It periodically sends “who has the token?” message
o Process pass this, when a process has the token it receives and modify
the identifier field and pass
o Monitor node get the identifier if no values in the field means token is
lost
14. Deadlock
The sequence of events are
1. Request
2. Allocate
3. Release
Two types of resources
1. Preemptable
2. Nonpreemptable
Conditions for deadlock
1. Mutual exclusive condition
2. Hold-and-wait condition
3. No-preemption condition
4. Circular-wait condition
Deadlock modeling
Deadlocks can be modeled using directed graphs
1. Directed graph
Is a pair(N,E), N is a nonempty set of nodes, E is a set of
directededges
15. 2. Path
A path is a sequence of nodes (a,b,c,…i,j) of a directed graph
(a,b), (b,c), …. (i,j) are directed edges
3. Cycle
A cycle is a path whose first and last nodes are same
4. Reachable set
The reachable set of a node a is the set of all nodes b such that a path
exists from a to b
5. Knot
A knot is a nonempty set K of nodes
The reachable set of each node in K is exactly the set K
A knot always contains one or more cycles
For deadlock modeling a directed graph is called a resource
allocation graph
Two types of nodes and edges for graph elements
1. Process node
Represents a process of the system
It is normally as a circle
2. Resource nodes
Shown as a rectangle with the name of the resource
16. 3. Assignment edges
Directed edge from a resource node to a process node
It signifies the resource is held by the process
In multiple units tail of an assignment edge touches one of the
bullets in the rectangle
4. Request edge
Directed edge from a process node to a resource node
It signifies the process made a request for a unit of the resource
type and is currently waiting for that resource
P2 P3
17. Acycleisnecessarycondition for adeadlock.
The presence of cycle is necessary condition for deadlock but
not sufficient.
Thisdiagramcontains cyclebut doesnot represent adeadlock.
WhenP3completesits processing.It release
R1. R1assignedtoP2.
P2completeits joband
releaseR2,R1.
R2allocatedtoP1.
NecessaryandSufficientConditionsfor Deadlock
18. If processes forming a cycle , and one or more resources Ri have
more than one unit, andaknot will bethere, deadlockoccurs.
P3request for R2.(P3,R2)addedto the graph.
This graph has two cycles (P1,R2,P2,R1,P1)and (P3,R2,P2,R1,P3)in knot
(P1,R2,P3,R1,P1)
• Necessary and sufficient condition for deadlock
canbesummarized asfollows:
• Acycleisnecessaryfor deadlock.
• If there is a only single unit in one Resource in
cycle.
• If more than oneunit arethere in cycle,then a
knotissufficientfor a deadlock.
19. Wait-for graph(WFG)
Wheneachresourcehasoneunit , simplified form of graphisused.
Conversionfrom allocation graphto aWFG,removingthe resourcenodes.
This simplification based on , a resource can always be identified by its
current owner ( processholdingit).
WFG is constructed only when each resource type has only a single
unit
A cycle is both a necessary and sufficient condition for deadlock in a
WFG
20. HandlingDeadlocksinDistributedSystems
Commonly used strategies to handle deadlock are as follows:
Avoidance–resourcesarecarefullyallocatedtoavoiddeadlocks
Prevention – constraints imposed in which processes request
resources in order to prevent deadlocks
Detection and recovery – allowed to occur and detection algorithm to
detectthemandresolvedbycertainmeans.
Two kind of distributed deadlocks
Resource deadlocks – when two or more process wait
permanently for resources held by each other
Communication deadlocks – set of process they are blocked
waiting for message from other process.
21. DeadlockAvoidance
The system dynamically considers every request and decides
whether it issafeto grant it at this point.
Deadlock avoidance usesome advance knowledge of the resource
usageof processes.
Followingstepsarefor deadlockavoidance:
When a process request for resource, even if the resource is
available for allocation. It is not immediately allocated to that
process.
Advance knowledge used to perform analysis to decide
whether process’srequest issafeor unsafe.
Whenrequest issafe,resourceallocated, otherwise deferred.
22. deadlock avoidance are based on the concept of safe and
unsafe states
safe state if it is not in a deadlock state and there exists some
ordering of the processes
the resource requests of the processes can be granted to run all of
them to completion
Any ordering of the processes that can guarantee the
completion of all the processes is called a safe sequence
A system state is said to be unsafe if no safe sequence exists
for that state
in a system there are a total of 8 units of a particular resource
type for which three processes P1, P2, and P3 are competing
the maximum units of the resource required by P1, P2, and P3
are 4, 5, and 6, respectively
currently each of the three processes is holding 2 units of the
resource
current state of the system, 2 units of the resource are free
23.
24. If resource allocation is not done carefully , the system move from a
safesate to unsafestate.
It isimportantto notethefollowing remarksaboutsafeandunsafe states:
Theinitial statein which noresourcesareyet allocatediscalledsafe state.
Safestate,the systemcanguaranteethat all processescanberunto completion.
An unsafe state is not a deadlock state, but it may lead to a deadlock state, the
systemcannotguaranteethat all processescanberun to completion.
25. Deadlock avoidance algorithms ensure that the system will
always remain in a safe state
Due to following reason, avoidancerarelyused:
1. Assumption of advance knowledge is available, however in
practice, processes rarely know in advance what their
maximum resource needswill be.
2. Number of processes not known in advance, because
dynamically varies.( userlogin ,logout)
3. Number of units changedynamically (machinecrash).
4. Restriction on resource allocation , cause degrades the system
performance.
26. DeadlockPrevention
Designingthe systemin awaythat deadlock becomeimpossible.
Prevention is different from avoidance because no runtime testing
(dynamically) of potential allocationsneedbeperformed.
Preventthe oneof the fournecessaryconditions:
1. Mutual exclusioncondition
2. Hold andwait condition
3. No-Preemption condition
4. Circular-wait condition
27. • MutualExclusion
Unfortunately it is not possible to prevent deadlocks by denying
mutual-exclusion.
Cannot be prevented for all resources. Some resources are intrinsically
non-sharablefor exampleprinter, andsomearesharable like CPU.
Example printer is a nonsharable resources
By spooling printer output several process can generate o/p at
the same time
It is not possible to prevent deadlocks by denying the mutual
exclusion condition.
Denial of the mutual exclusion condition for deadlock prevention is
rarely used.
28. Hold and wait ( Collective Requests )
Thismethod deniesthe hold-and-waitcondition.
Wemust guaranteethat whenever aprocessrequestsaresource,it
doesnot hold anyotherresources.
Followingpolicies maybeusedto ensurethis:
1. A process must request all of its resources before it begins execution.
If all the needed resources are available , they are allocated to it.
If one or more resources are not available , none will be allocated and
process would just wait.
2. Instead of requesting all its resources before its execution starts, a process
request resources during its execution.
It request resources only when it holds no other resources
If the process is holding some resources, it first releasing all of them and
then re-requesting all the necessary resources
29. The second policy has the following advantages over the
first one:
1. Many processes do not know how many resources they
will need until they have started running
2. A long process may require some resources only toward
the end of its execution.
The collective request method of deadlock prevention is
simple and effective but has the following problems:
1. Low resource utilization – a process may hold many
resources but may not use it for long time.
2. It may cause starvation of a process – needs many
resources, but whenever it makes a request for resource,
one or more is not available.
3. The method raises an accounting question – when a
process holds resources for extended periods during
which they are not used , cost of idle resources.
30. Circularwaitcondition(ordered requests)
Each resource (type) is assigned a global number to impose total ordering.
Impose a total ordering of all resource types , and require that each process
can only requests resources in an increasing order of enumeration.
Process should not request a resource with a number lower than is already
held resource.
If process request a resource type j and process already held
resource type whose number is i then, j > i
Single request will be enough for the same resource type.
It has proven that with this ,graph can never have circular-wait.
If tape drive =1 , disk drive = 5, printer = 12,
After getting tape drive process can request for the disk drive, after disk drive
process can request for the printer.
But it a process have the number =5, it cannot request for the number=1 for
tape drive.
31. Preemptioncondition( resourceswillbepreempted)
A preemptable resource is one whose state can be easily saved and
restored later.
A resource temporarily taken away from the process without harm
to the computation performed bythisprocess.
CPU,Main Memory arepreemptableresources.
If the resourcesarepreemptable,deadlockscanbeprevented.
Twopolicies:
1. when aprocess requests for aresource, and resource is not available.
Its already held resources taken away from it. And the process is
blocked. The process is unblocked when the resources (requested by
it, andpreemptedfrom it) availableandallocatedto it.
32. 2. When a process requests a resource that is not currently available,
the system checks, if the requested resource is currently held by another
process that is already blocked and waiting for other resources.
If so , the requested resource is taken away from the waiting process and give to
the requesting process,
otherwise condition-1 applied.
The transaction-based deadlock prevention method
The transaction mechanism allows a transaction (process) to be aborted
(killed) without any ill effect
Each transaction (process) is assigned a unique priority number by the
system
When two or more transactions compete for the same resource, priority
numbers used to break the tie.
Lamport’s algorithm to use unique timestamps for transaction
Timestamps used as its priority number
A transaction having lower value of timestamp have higher priority.
33. Rosenkrantz et al. proposed the following deadlock prevention
schemes
1. Wait-die scheme
If a transaction Ti requests a resource that is held by another transaction Tj
Ti is blocked(wait) if its timestamp is lower than that of Tj
Otherwise it is aborted (dies)
Example: Three transaction T1, T2 and T3.
If T1 request a resource that is currently held by T2.
T1 will be blocked and will wait until the resource is voluntarily released by
T2
If T3 requests a resource held by T2, T3 will be aborted.
2. Wait-wound scheme
If a transaction Ti requests a resource currently held by another transaction
Tj
Ti is blocked (waits) if its timestamp is larger than that of Tj
Otherwise Tj is aborted (wounded by Ti)
Example: Three transaction T1, T2 and T3.
If T1 request a resource that is currently held by T2.
The resource will be preempted by aborting T2 and will be given to T1
If T3 requests a resource held by T2, T3 will be blocked and will wait until the
resource is voluntarily released by T2.
34. In the wait-die scheme,
a younger transaction is aborted when it requests for a
resource held by an older transaction
The aborted transaction will be restarted after a
predetermined time and will be aborted again if the older
transaction is still holding the resource.
This cycle may be repeated several times
This problem solved by using an implementation mechanism
that an aborted transaction is restarted only when its
requested resource becomes available
In the wait-wound scheme,
when a younger transaction is aborted (wounded) by an
older transaction, it will be restarted after a predetermined
time
to avoid starvation,
a transaction should not be assigned a new timestamp when
it is restarted after being aborted
35. DeadlockDetection
Uses algorithm that keeps examining state of system to determine
weather a deadlock has occurred.
When deadlock has occurred system takes action to recover.
Algorithms are same for centralized as well as distributed.
Uses resource allocation graph and searching for cycle or knot
depending upon single or multiple units of resources.
Following steps are needed to construct Weight For Graph(WFG).
1. Construct separate Resource allocation graph for each site.
Resource node exists for all local resources and process node
exists for all processes that are either holding or waiting for
resource.
2. Construct WFG by removing resources and collapsing edges.
3. Take union of all WFG of all sites and construct single global WFG.
36. Two sites, site 1 with 2 resources R1, R2 and site 2 with 1 resource R3.
P1 is holding R1 and requesting for R3.
P2 is holding R2 and requesting for R1.
P3 is holding R3 and requesting for R2
Union of WFG of two sites will show either deadlock exists or not. Local WFG does not
contain cycle while Global has.
Difficulties in implementing deadlock detection is Maintaining WFG of each site is
difficult.
Most important feature of deadlock detection algorithm is correctness which
depends on these properties.
1. Progress Property - Deadlocks must be detected in finite amount of time.
2. Safety Property - Detected deadlock must exist.
Message delays and out-of-date WFG cause false cycles to be detected.
It results in detection of deadlocks that do not exist called phantom
deadlocks.
37.
38. Three commonly used techniques for organizing WFG in a distributed system are.
Centralized Algorithms.
Distributed Algorithms
Hierarchical Algorithms.
Centralized Approach
Local coordinator at each site that maintains WFG of its local resources.
Central coordinator that is responsible for constructing union of all WFG.
also known as a centralized deadlock detector
Central coordinator constructs global EFG from information received form local
coordinator of all sites.
Deadlock detection is performed as follows.
1. If cycle exists in local WFG of any site, it represents local deadlock. Such deadlocks
are detected and resolved by local coordinator.
2. Deadlocks involving resources at two or more sites get reflected as cycles in global
WFG. Such deadlocks are detected and handled by central coordinator.
39. In centralized approach the local coordinators send local state
information to the central coordinators in the form of messages.
Following methods used to transfer information from local
coordinators to the central coordinator:
1. Continuous Transfer: A local coordinator sends a message
providing the update in the local WFG , whenever an new edge
is added or deleted
2. Periodic Transfer: A local coordinator sends message after
fixed time when number of changes have occurred.(in order to
reduce messages)
3. Transfer on Request: on request of central coordinator.
Central coordinator invokes cycle detection algorithm
periodically and requests information from each site just
before invoking algorithm.
40. Drawbacks in centralized deadlock detection:
1. Failure of central coordinator. Back up can resolve issue.
2. Central coordinator will become performance bottle
neck in large system having to many sites.
3. It may detect false deadlocks.
Example how this algorithm lead to the detection of false
deadlocks, consider the previous fig.
3 processes(P1,P2,P3) compete for 3 resources(R1,R2,R3)
Step 1: P1 requests for R1 and R1 is allocated to it.
Step 2: P2 requests for R2 and R2 is allocated to it.
Step 3: P3 requests for R3 and R3 is allocated to it.
Step 4: P2 requests for R1 and waits for it.
Step 5: P1 requests for R2 and waits for it.
Step 6: P1 releases R1 and R1 is allocated to P2.
Step 7: P1 requests for R3 and waits for it.
41. The method of continuous transfer is employed by the algorithm, the sequence of message
send to the central coordinator:
m1:from site S1 to add edge (R1,P1)
m2:from site S1 to add edge (R2,P2)
m3:from site S2 to add edge (R3,P3)
m4: from site S1 to add edge(P2,R1)
m5: from site S1 to add edge(P3,R2)
m6: from site S1 to delete edges (R1,P1) and (P2,R1) and edge (R1,P2)
m7: from site S2 to add edge (P1,R3)
If all these messages are in order then no problem.
If message 7 from site 2 comes earlier than message 6 from site 6 than central coordinator
will incorrectly conclude that deadlock has occurred and will start to recover.
In this example we followed continuous transfer same problem will also be with other two
methods.
Solution: assign unique global timestamp with message.
Central coordinator send message to each site if some one has time stamp earlier than
received message, site with minimum will reply and other site with negative reply.
42. (a) Resource allocation graphs after step 5
(b) Resource allocation graphs after step 7
(c) Resource allocation graph of the central coordinator showing false deadlock
if message m7 is received before m6 by the central coordinator
43. HierarchicalApproach
Most WFG cycles are very short.
90% of all deadlock cycles involve only two processes.
So centralized approach seems less attractive because
of time and overhead involved in assembling local
WFG at central coordinator.
Deadlock should be detected by a site located as close as
possible to sites involved in cycle to minimize
communication cost.
Hierarchical approach solves the above problems
44. Uses logical hierarchy(tree) of deadlock detectors.
Deadlock detectors are called controllers.
Each controller is responsible for deadlocks that involves sites falling within
its range.
centralized approach in which the entire global WFG is maintained at a
single site
In the hierarchical approach it is distributed over a number of different
controllers.
Each site has its own local controller that maintains its own local graph.
WFG is maintained by a particular controller is decided according to the
following rules.
Each controller that forms a leaf of the hierarchy tree maintains local
WFG of single site.
Each non-leaf controller maintains WFG that is union of WFGs of its
immediate children in hierarchy tree.
45.
46. Each site of system shares equal responsibility for deadlock
detection.
Two Types of algorithms:
1. WFG based Distributed algorithm for deadlock detection.
2. Probe based Distributed algorithm for deadlock detection.
WFG based Distributed algorithm for deadlock detection
Each site maintains its own WFG.
To model waiting situations that involves external processes,
modified form of WFG is used
An Extra node Pex is added to local WFG of each site,
And this node is connected to WFG of corresponding site in
following manner.
1. An edge(Pi, Pex) is added if processes Pi is waiting for resource
in another site held by any other process.
2. An edge(Pex,Pj) is added if Pj is a process of another site that is
waiting for a resource currently held by process of this site.
Fully Distributed Approaches for deadlock detection
47. 1. in the WFG of site S1, edge (P1,Pex) is added because process P1 is waiting for a resource in site
S2, that is held by process P3, and edge(Pex,P3) is added because process P3 is process of site S2,
that is waiting to acquire a resource currently held by process P2 of site S1.
2. in the WFG of site S2, edge (P3,Pex) is added because process P3 is waiting for a resource in site
S1, that is held by process P2, and edge(Pex,P1) IS Added Because process P3 is process of site
S2, that is waiting to acquire a resource currently held by process P2 of site S1.
48. If local WFG contains a cycle that does not involve node
Pex, a deadlock that involves only local process of that site
has occurred.
Such deadlocks are handled locally.
If local WFG contains a cycle that involves node Pex, there
is possibility of distributed deadlock that involves
process of multiple sites.
For confirmation deadlock distribution algorithm is
invoked by site whose WFG contains a cycle involving node
Pex.
49. The algorithm works below:
1. A cycle involving node Pex is detected in the WFG of site Si
2. This cycle must be the form (Pex, Pi, Pj, …., Pk, Pex)
3. It means process Pk is waiting for an external resource that belongs to
some other site (Sj)
4. Site Si sends a deadlock detection message to site Sj
5. This message is only part of WFG that forms the cycle
6. On receiving message site Sj updates its local WFG by adding those
edges of the cycle that do not involve Pex to its WFG
7. If the newly constructed WFG of site Sj contains a cycle that does not
involves node Pex, a deadlock exists
8. If a cycle involving node Pex is found in the newly constructed WFG of
site Sj, Sj sends deadlock detection message to appropriate site (Sk).
50. A problem associated with the above algorithm is that two sites may
initiate the deadlock detection algorithm independently
The result will be that both sites will update their local WFGs and
search for cycles
both may initiate a recovery procedure that may result in killing
more processes than is actually required to resolve the deadlock
This leads to extra overhead in unnecessary message transfers and
duplication of deadlock detection jobs
One way to solve the problem is to assign a unique identifier to each
process Pi [denoted as ID(Pi)]
when a cycle of the form (Pex , Pi , Pj ,.. , Pk, Pex ) is found in the local
WFG of a site
this site initiates the deadlock detection algorithm by sending a
deadlock detection message to the appropriate site only if
ID(Pk)<ID(Pi)
Otherwise, this site does not take any action and leaves the job of
initiating the deadlock detection algorithm to some other site
51. Probe based Distributed algorithm for deadlock detection
Best algorithm for detecting global deadlocks in distributed
system.
Algorithm allows a process to request multiple resources at a
time.
When a process requests for a resource or resources fails
to get requested resource and times out, it generates
special probe message and sends it to process holding the
requested resources.
Probe message contains following fields.
1. The identifier of process just blocked.
2. The identifier of process sending message.
3. The identifier of process to whom the message is being sent.
52. On receiving a probe message, receipt checks to see if it itself is waiting for
any resource or resources.
If not this means that receipt is using the resource requested by the process
that sent probe message to it.
Receiver simply ignores probe message.
On the other hand if receipt is waiting for any resource it passes the probe
message to the process or processes holding the resource for which it is
waiting . However probe message is forwarded.
Receipt modifies its field in following manner.
1. The first field is left unchanged.
2. The receipt changes the 2nd field to its own process identifier.
3. 3rd field is changed to identifier of process that will be new receipt of this
message.
Every new receipt of probe message repeats this procedure.
If probe message returns back to its original sender a cycle exists and
system is deadlocked.
53. Attractive Features:
1. easy to implement, since message is of fixed length and requires
few steps for computation.
2. Low overhead
3. No need of graph construction
4. False deadlocks are not detected.
5. No specific structure required among processes.
54. Waysforrecoveryfromdeadlock
Asking for operator intervention
Termination of process or processes.
Rollback of processes.
1. Asking for operator intervention:
system assist the operator in decision making for recovery by
providing him list of processes involved in deadlock.
It is handled manually. Console is used to continuously monitor
smooth running.
Every site has an operator to handle deadlock.
Drawbacks:
Not used in modern systems.
Not suitable for distributed environment because each site operator
will take some action for recovery.
If operator of single site is informed. It may favor it’s own processes.
Operator of one site may not have right to interfere with a process of
other
55. 2. Termination of process or processes:
•Simplest way to recover deadlock automatically by killing one or more
processes and reclaim the resources held by them, then be reallocatted
•algorithms of this type analyze resource requirements and interdependencies
of processes involved in deadlock cycle and then select a set of processes
which if killed can break cycle.
3. Rollback of processes:
• killing of processes restarting from start is expensive specially when the
process has already run for long time.
• To reclaim a resource from process that were selected for being killed rollback
the process to point where resource was not allocated to the process.
• Processes are check pointed periodically.
• Process state memory image and list of resources held by it are written to a
file at regular interval.
• So in case of deadlock process can be restarted from any of check points.
56. Issues In RecoveryFromDeadlock
• Selection of victim:
• Deadlock is broken by killing or rolling back one or more processes. These
process are called victims.
• Selection of victims is normally based on two major factors:
1. Minimization of recovery cost:
Processes whose termination/rollback will incur minimum recovery cost
must be selected.
Unfortunately it is not possible to have universal cost function.
Each system should determine its own cost function to select victim.
Factors:
1. Priority of processes.
2. Nature of processes ( interactive or batch)
3. Length of service already received and expected length of service
further needed by processes.
4. The number and types of resources held by processes
5. Total number of processes that will be affected.
57. 2. Preventionofstarvation:
Same processes may be repeatedly selected as victim on the basis
minimization of recovery cost and may never complete called starvation.
Raise the priority of processes every time it is victimized.
Include number of times a process is victimized as parameter to cost
function.
Use of Transaction mechanism:
After a process is killed or rolled back for recovery from deadlock, it has
to be rerun
Rerunning a process from rollback state may not always be safe.
Operations performed by that process may be non idempotent.
It must be used with only those processes which will not cause ill effects.
58. ElectionAlgorithms
Election algorithms are meant for electing a coordinator process from
among the currently running processes
if the coordinator process fails due to the failure of the site on which it is
located, a new coordinator process must be elected to take up the job of the
failed coordinator
Election algorithms are based on following assumptions
1. Each process in system has unique priority number.
2. Whenever an election is held, process having highest priority
number among the currently running processes is elected as
coordinator.
3. On recovery, a failed process can take appropriate actions to rejoin the
set of active process.
• Types:
1. Bully Algorithm
2. Ring Algorithm
59. BullyAlgorithm
When a process(say Pi) sends a request message to coordinator and does not
receive a reply within a fixed time out period, it assumes that coordinator has
failed.
It initiates election by sending an election message to every process with
higher priority no than itself.
If Pi does not receive response in time out means it has highest priority.
It will become coordinator and will inform all processes through message.
If Pi receives reply means other processes with higher priority are available
and does not take any decision and waits for final result
When Process Pj receives an election message.
It informs sender that is alive and now Pj will do election and will become
coordinator if it has highest priority no.
Else Pj will initiate message and this will continue.
60. As part of the recovery action,
a failed process (say Pk ) must initiate an election on recovery.
If the current coordinator's priority number is higher than
that of Pk
then the current coordinator will win the election initiated by Pk
and will continue to be the coordinator
if Pk priority number is higher than that of the current
coordinator, it will not receive any response for its election
message
So it wins the election and takes over the coordinator's job
from the currently active coordinator
the active process having the highest priority number always
wins the election
Hence the algorithm is called the "bully" algorithm
61. Ring Algorithm
Processes are arranged in logical ring.
Every process in the system knows structure of ring.
If successor of sender process is down, it can be skipped until active member is
achieved.
When a process sends (Pi ) requests message to coordinator and it is down it will wait
for time out, it initiates election by sending election message to successor.
Message contains priority no of process Pi
On receiving the election message,
the successor appends its own priority number to the message and passes it on to the next active
member in the ring.
This member appends its own priority number to the message and forwards it to its own successor
the election message circulates over the ring from one active process to another and
eventually returns back to process Pi
Pi recognizes its own message due to first priority no.
it elects the process having the highest priority number as the new coordinator.
62. It then circulates coordinator message to all active processes to tell
them all the other active processes who the new coordinator is
It deletes coordinator message after complete round when message
comes back to process Pi
When a process (say Pj) recovers after failure, it creates an inquiry
message and sends it to its successor
The message contains the identity of process Pj
If the successor is not the current coordinator, it simply forwards the
enquiry message to its own successor
the inquiry message moves forward along the ring until it reaches the
current coordinator.
On receiving an inquiry message, the current coordinator sends a reply to
process Pj, informing that it is the current coordinator