Deadlocks Group Project

advertisement
DEADLOCKS GROUP PROJECT
Branden, Dalton, Dhyan, Jonathan, and Tyler
WHAT IS A DEADLOCK?
 A deadlock is defined as a situation in which two or more processes find
themselves blocking one another and there is no way to avert the situation.
Formal Definition: A set of processes is deadlocked if each process in the set is waiting
for an event that only another process in the set can cause.
 Example: Two processes want to record a document onto a disc.
 Both processes ask to use the scanner in different ways and both are given access.
 When one moves to record the file it finds it cannot due to the other process holding it
 Loop will continue indefinitely and no progress will be made.
IS A DEADLOCK LIMITED TO ONE
MACHINE?
 Deadlocks can occur across multiple machines just as easily as in one.
 If multiple devices remotely request the use of external devices then deadlocks
can occur as well.
 Many offices LAN networks are connected to external devices that require remote
access.
This picture shows a deadlock
in traffic for a one lane portion
of road.
PREEMPTABLE & NONPREEMPTABLE
RESOURCES
 Resources come in two types: Preemptable and Nonpreemptable.
 Preemptable Resources are those that can be taken away from the process owning it
with no ill effects.
 Example: Two processes sharing a printer due to preemptive behaviors.
 Nonpreemptable Resources are resources that cannot be taken away from their current
owner without potentially causing failures.
 Example: Burning information to a disc via a burner, and suddenly taking the burner away from the
resource. This would lead to file corruption and a messed up disc.
 Files are determined to be Preemptable or Nonpreemptable dependent on the context
of the given situations.
What might some examples of these situations be?
RESOURCE DEADLOCKS
 A resource deadlock occurs when a member is waiting on a process that is currently
held by another deadlocked member.
 Conditions for a Resource Deadlock:
 1. Each resource is either currently assigned to exactly one process or is available.
 2. The Processes currently holding resources that were granted earlier can request new resources.
 3. Previously granted resources cannot forcibly be taken away from a process. They must be
released by the process holding them.
 4. Must be a circular chain of 2+ processes, each waiting for a resource held by the next member.
 All of these conditions must be met for a Resource Deadlock to occur.
DEADLOCK MODELING
 When it comes to modeling deadlocks there are two basic images that we can
use.
 Circles are used to represent a Process Node
 Squares are used to represent a Resource Node
 A directed arc from a process to a resource node means that the process is
currently waiting for the resource to finish with its current source.
What is happening in the graph to the right?
Are there any potential deadlocks?
STRATEGIES FOR DEALING WITH DEADLOCKS
 In general, there are four basic strategies used for dealing with deadlocks”
1. Ignore the problem. “If I ignore it, it will ignore me” mentality
2. Detect and Recover. “Let them happen, detect, then take action”
3. Dynamic Avoidance. “Carefully allocating resources”
4. Prevention, by structurally negating one of the four conditions
How would you go about handling a deadlock?
THE OSTRICH ALGORITHM
 The simplest approach to dealing with a deadlock.
 “Stick your head in the ground and pretend there is no problem”
 People will react in different ways to this approach:
 Some find it unacceptable (Deadlocks must be prevented!)
 Some will inquire about specifics (how often it crashes, size of crashes, etc.)
 Others will go along with nothing being wrong at all (other ostriches)
DEADLOCK DETECTION AND RECOVERY
 A technique used in which the system does not attempt to seek out deadlocks;
rather it waits for them to occur.
 Upon detecting a deadlock, system will take action recover after the fact.
 Is proven to be a successful means of resolving problems however, some can slip past it
still.
Do you see any problems in the Detection Recovery Method?
Lazy Detective could lead
to issues!
REVIEW QUESTIONS OF 6.1-6.4
 What is the definition for a deadlock?
 What are the different types of deadlocks that can occur?
 How do we model deadlocks in graphs?
 What are two different strategies for handling deadlocks and how do they differ?
 Which Strategy do you find to be more effective?
DEADLOCK AVOIDANCE
 Requires knowing certain information ahead of time
 This requirement makes avoidance very difficult because process often don’t know
beforehand how many children processes it will need, what resources it will use, etc.
 Strategies:
 Trajectories
 Safe/Unsafe States
 Banker’s Algorithm
 These strategies aren’t commonly used in their current form, but many real-world
heuristics are based on them.
RESOURCE TRAJECTORIES
 Graph is created that plans a “trajectory” of how resources will be used and
designs a “path” that will keep the system out of a deadlock
 These trajectories help guide the processes in a way that keeps the system safe
 The trajectories and paths are difficult to create because it is difficult to know
what resources the process will want in the future
 Trajectory can be used to decide if granting a resource will lead to a deadlock
RESOURCE TRAJECTORIES
This is an example trajectory
map for two processes. The
path created can be used to tell
if a deadlock is about to happen
and can be used in an attempt
to steer the system away from
a deadlock.
RESOURCE TRAJECTORIES
 Graphs with mapped trajectories give a visual interpretation
 The shaded zones represent things that can lead to a deadlock
 Things that cause shaded zones are resource shortages, which is the main thing we’ve
been discussing, but a shaded zone may also indicate an impossible action such as
trying to output to the keyboard
 Often times, if the trajectory runs along the graph in a single direction for too
long, the processes will be switched. In this way, the trajectories also help give
processes a fair turn at running, which can intrinsically help reduce deadlocks
SAFE AND UNSAFE STATES
 There are two states that a system can be in:
 Safe
 The scheduling order allows the system to run all processes to completion without any issues
 Unsafe
 It is not guaranteed that the system will be able to finish all the processes without a deadlock.
A system being in an unsafe state does not necessarily mean that a deadlock is going to occur
 The safe and unsafe state concept is combine with the graphs, to try to avoid the
shaded spaces. Shaded spaces represent unsafe states, and free spaces represent
safe ones. The system tries to keep the trajectory in safe states so that the system
will remain stable
BANKER’S ALGORITHM
The Banker’s Algorithm has
that name because it behaviors
like a banker watching over a
loan. In the case of computer
science, the banker is the
operating system, the person
borrowing the money is like the
process, and the money is like
resources such as a disk, printer,
etc.
BANKER’S ALGORITHM
 As explained in the previous slide, the operating system is like the banker in our metaphor.
A major function of a banker is to assess risks and decide how much money to lend to
somebody.
 Operating systems act in the same fashion, deciding weather or not it’s risky to grant a
resource to a process. The operating system will deny giving a resource to a process if it
believes that granting the resource will push the system closer to an unsafe state.
 Also like a banker, the Banker’s Algorithm grants resource requests as the processes
request them, not ahead of time.
 A banker will only lend as much that is asked for, and as much that is safe to lend out. If you
borrowed $5,000.00, a banker won’t just send you an extra $5,000.00 that you haven’t asked
for, in the same way that an operating system doesn’t assign resources that haven’t been
asked for by a process.
 According to the Banker’s Algorithm, the OS must always have enough resources on hand
to complete at lease one process (so that it will then release its resources to other
processes that are still running).
BANKER’S ALGORITHM
 Most algorithms assume that there is only one resource of each type available,
and the banker’s algorithm is no exception, but it can be generalized to work with
multiple resources
 As stated in the intro to this section, it’s not used much, because like process
information, demands, and trajectories, it’s very difficult to know how much risk
an action will generate ahead of time, and if that action will push the system state
closer to an unsafe state
 A popular heuristic related to the banker’s algorithm is used in networking to
handle user loads. For example, if a network is at 70% capacity, the network will
throttle new users so that the remaining 30% of network space will be enough to
allow the original users to finish their work. When those original users finish, then
the network load will lower, and the throttle will be removed.
REVIEW OF SECTION 6.5
 What strategies are used in deadlock avoidance?
 Why are they not commonly used in the real world?
 What is a trajectory and how is it used?
 Does an unsafe state represent a deadlock?
 What do the pieces involved with banking equate to in an operating system?
Download