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. |