Lecture 13&14- Deadlocks Flashcards
Definition of deadlock
Deadlock is a situation when one or more processes get stuck
e.g. infinite loop
What are the 4 ways to handle deadlocks?
Ignore.
Detect and fight.
Avoid.
Prevent.
What is Deadlock detection?
The operating system runs a special software that can recognise that a deadlock has happened.
Once a deadlock has been detected, special measures are taken to its elimination.
What are the ways of elimination of the detected deadlock?
Preemption. A resource is (temporarily) taken from one of the processes currently holding it and transferred to another process. Example: part of data is recorded on a disc and a
block of RAM gets free.
Drawback: some resources are non-preemptable (e.g. printer).
Rollback. Each program is checkpointed periodically. The program is rolled back to a point in time prior to deadlock
and the allocation of resources is changed.
Killing processes. Normally this is done manually as the system cannot decide which process to kill.
What is Deadlock avoidance?
The system has a smart scheduling policy of running programs so that deadlocks are avoided.
For example, such smart system would not let the programs in the last example to get into a deadlock.
Requires knowledge about future operations of processes.
This knowledge is not easy to get.
What is Deadlock prevention?
A system is designed in a way that deadlocks in principle cannot occur.
Imposes strict requirements on programs running in this system.
Programs of the last example will be impossible to run.
Difference from deadlock avoidance: in the latter deadlocks are possible in principle but the system tries to foresee and
avoid them.
Dealing with deadlocks in real systems?
A standard principle of engineering: a potential trouble has to be explicitly dealt with only if the negative effect of letting it happen significantly overweights the price of its elimination.
Deadlocks do not do much harm to common users of personal computers.
Therefore OS like Linux and Windows ignore deadlocks(although there are Linux utilities that allow to detect deadlocks).
On the other hand, deadlocks can have devastating effects on real-time safety critical systems (medical equipment, air crafts, etc.) and large database systems (banking salary
computation).
What are the Processes and resources?
The standard terminology related to deadlocks involves two main notions processes and resources.
We have met both these notions in the previous lectures.
The notion of resource is very broadly understood: block of memory, printer, scanner, etc.
A process during its execution can hold resources and release them.
A deadlock occurs if there is a group of processes each wants to get a resource currently being held by another process of
this group.
How to Detecting a deadlock with a single resource of each type?
Single resource of each type means: one printer, one disc, one scanner, etc.
The OS looks at the current state of the processes in the given moment of time of time and decides if there is a deadlock.
What is the information used by the system:
The list of processes.
The list of resources
The relationship between the given process and the given resource: holding, requesting, neither of them.
We will see a deadlock detection algorithm based on the above information
What is the deadlock detection algorithm?
The input is represented in the form of a graph
Nodes correspond to processes and resources.
There is an arc from the node corresponding to resource R to
the node corresponding to process P if P is currently holding R.
There is an arc from P to R if P is requesting R.
The system is in a deadlock if an only if the above graph has a directed cycle
How use of deadlock avoidance?
Each time a resource request is made the system analyses the safeness of the state occurring after the requests has been
granted.
If the considered state is not safe then the request is either denied or delayed.
What is Deadlock prevention?
Four necessary conditions of deadlock existence.
1 Mutual exclusion. Each resource can be assigned to at most
one process.
2 Hold and wait. Processes currently holding the resources may request more resources.
3 No preemption. Resources granted cannot be forcibly taken away before the process has released them.
4 Circular wait. There is a circular chain of processes waiting for a resource held by the next member of the chain.
A system preventing deadlocks makes one of these condition
impossible to occur.
How to Elimination of the Hold-and-Wait condition?
Each program asks for all the resources at the beginning of its run.
This approach is possible only in batch systems: in interactive systems the user requests are unpredictable.
How to Elimination of the circular wait condition?
All the resource units are thoroughly enumerated.
The process can ask resources only according to the enumeration order: a process can ask for a new resource only if its number is greater than the numbers of the resources
already held.
What is Livelocks and starvation?
Live lock is just a deadlock where a process performs infinite loop and not blocked.
Starvation is a situation where a process never gets an opportunity to run. Occurs due to the poor scheduling policy