1. 死锁预防:
死锁预防意味着阻止死锁发生所需的四个条件中的至少一个。如果我们能够阻止其中任何一个,那么就可以防止死锁。
需要阻止的四个条件是:-
- 互斥
- 保持并等待
- 无抢占
- 循环等待
假脱机和非阻塞同步算法用于防止上述情况。在死锁防止中,所有请求都在有限的时间内被授予。
2. 避免死锁:
在死锁避免中,我们必须在死锁真正发生之前对其进行预测,并确保系统不会进入不安全状态。如果仔细分配资源,就有可能避免死锁。为了避免死锁,我们使用银行家和安全算法进行资源分配。在避免死锁的过程中,将需要的每种类型的最大资源数在过程开始时说明。
死锁预防和死锁避免的区别:
S.NO. | Factors | Deadlock Prevention | Deadlock Avoidance |
---|---|---|---|
1. | Concept | It blocks at least one of the conditions necessary for deadlock to occur. | It ensures that system does not go in unsafe state |
2. | Resource Request | All the resources are requested together. | Resource requests are done according to the available safe path. |
3. | Information required | It does not requires information about existing resources, available resources and resource requests | It requires information about existing resources, available resources and resource requests |
4. | Procedure | It prevents deadlock by constraining resource request process and handling of resources. | It automatically considers requests and check whether it is safe for system or not. |
5. | Preemption | Sometimes, preemption occurs more frequently. | In deadlock avoidance there is no preemption. |
6. | Resource allocation strategy | Resource allocation strategy for deadlock prevention is conservative. | Resource allocation strategy for deadlock prevention is not conservative. |
7. | Future resource requests | It doesn’t requires knowledge of future process resource requests. | It requires knowledge of future process resource requests. |
8. | Advantage | It doesn’t have any cost involved because it has to just make one of the conditions false so that deadlock doesn’t occur. | There is no system under-utilization as this method works dynamically to allocate the resuorces. |
9. | Disadvantage | Deadlock prevention has low device utilization. | Deadlock avoidance can block processes for too long. |
10. | Example | Spooling and non-blocking synchronization algorithms are used. | Banker’s and safety algorithm is used. |