The Difference Between Deadlock Prevention and Deadlock Avoidance
Deadlock Prevention:
Preventing deadlocks by constraining how requests for resources can be made in the system and how they are handled (system design). The goal is to ensure that at least one of the necessary conditions for deadlock can never hold.
Deadlock Avoidance:
The system dynamically considers every request and decides whether it is safe to grant it at this point, The system requires additional apriori information regarding the overall potential use of each resource for each process. Allows more concurrency.
The main difference between deadlock prevention and deadlock avoidance is that deadlock prevention ensures that at least one of the necessary conditions to cause a deadlock will never occur while deadlock avoidance ensures that the system will not enter an unsafe state.
What is Deadlock Detection?
Deadlock detection is the process of actually determining that a deadlock exists and identifying the processes and resources involved in the deadlock.
The basic idea is to check allocation against resource availability for all possible allocation sequences to determine if the system is in deadlocked state (Banker’s algorithm).
Why Windows and Unix designers not include any deadlock prevention/detection in their Operating System?
Deadlock Prevention:
Prevent at least one of mutual exclusion, circular wait, hold and wait, no preemption from happening.
1.Why not prevent mutual exclusion from happening : oh, think about printers, then need exclusive access.
2.Why not prevent circular wait from happening : We need to some total ordering. For ex: In order to request Resource 1, a process must release all Resource i such that i >= j. But think about determining the ordering. A challenge? yes.
3.Why not prevent no preemption : Again think about a printer and preemption together.
4.Why not hold and wait should be prevented : Think of methods to do this, may lead to starvation.
Deadlock Avoidance :
Do not allow the system to go in deadlock state, avoid it. For this the system need some additional information about the processes and the resources they are going (will or may) to request. Difficult. No?
Deadlock detection and recovery :
Detection is fairly straightforward but what about recovery? It either requires aborting some process (es) or preempting some resource, attractive? No.
To Sum up, there are too much to do for an Operating System (Windows, Unix) to handle deadlock situation.
So, what will Operating System do???
Ostrich algorithm:stick your head in the sand and pretend there is no problem at all. (装作什么都没发生 : )
-
Engineers ask how often the problem is expected, how often the system crashes for other reasons, and how serious a deadlock is. If deadlocks occur on the average once every five years, but system crashes due to hardware failures, compiler errors, and operating system bugs occur once a week, most engineers would not be willing to pay a large penalty in performance or convenience to eliminate deadlocks.
-
Most operating systems, including UNIX and Windows, just ignore the problem on the assumption that most users would prefer an occasional deadlock to a rule restricting all users to one process, one open file, and one of everything.
-
The problem is that the price is high, mostly in terms of putting inconvenient restrictions on processes.
So, if deadlock happens, operating system (Windows&Unix) will do nothing and leave the choice to user (just restart).
Reference:
https://pediaa.com/what-is-the-difference-between-deadlock-prevention-and-deadlock-avoidance/
quora.com/Why-dont-Windows-and-Unix-recover-from-deadlock-Why-is-there-no-deadlock-detection-and-recover-algorithm-used
https://posteducation.wordpress.com/2013/05/26/the-ostrich-algorithm-to-a-best-techniques/