什么是死锁_什么是死锁?

什么是死锁

Deadlocks are a set of blocked processes each holding a resource and waiting to acquire a resource held by another process.

死锁是一组阻塞的进程,每个进程持有一个资源并等待获取另一个进程持有的资源。

Deadlocks in Operating Systems

如何避免死锁 (How to avoid Deadlocks)

Deadlocks can be avoided by avoiding at least one of the four conditions, because all this four conditions are required simultaneously to cause deadlock.

可以通过避免至少四个条件之一来避免死锁,因为同时需要所有这四个条件才能导致死锁。

  1. Mutual Exclusion

    互斥

    Resources shared such as read-only files do not lead to deadlocks but resources, such as printers and tape drives, requires exclusive access by a single process.

    诸如只读文件之类的共享资源不会导致死锁,但是诸如打印机和磁带驱动器之类的资源需要通过单个进程进行独占访问。

  2. Hold and Wait

    保持并等待

    In this condition processes must be prevented from holding one or more resources while simultaneously waiting for one or more others.

    在这种情况下,必须防止进程在等待一个或多个其他资源的同时保留一个或多个资源。

  3. No Preemption

    无抢占

    Preemption of process resource allocations can avoid the condition of deadlocks, where ever possible.

    抢占进程资源分配可以尽可能避免死锁的情况。

  4. Circular Wait

    循环等待

    Circular wait can be avoided if we number all resources, and require that processes request resources only in strictly increasing(or decreasing) order.

    如果我们对所有资源进行编号,并且要求进程仅按严格增加(或减少)的顺序请求资源,则可以避免循环等待。

处理死锁 (Handling Deadlock)

The above points focus on preventing deadlocks. But what to do once a deadlock has occured. Following three strategies can be used to remove deadlock after its occurrence.

以上几点着眼于防止死锁。 但是一旦发生僵局该怎么办。 以下三种策略可用于消除死锁。

  1. Preemption

    抢占

    We can take a resource from one process and give it to other. This will resolve the deadlock situation, but sometimes it does causes problems.

    我们可以从一个过程中获取资源,然后将其分配给其他过程。 这样可以解决僵局,但有时确实会导致问题。

  2. Rollback

    回滚

    In situations where deadlock is a real possibility, the system can periodically make a record of the state of each process and when deadlock occurs, roll everything back to the last checkpoint, and restart, but allocating resources differently so that deadlock does not occur.

    在极有可能发生死锁的情况下,系统可以定期记录每个进程的状态,并且在发生死锁时,将所有内容回滚到最后一个检查点,然后重新启动,但以不同的方式分配资源,以免发生死锁。

  3. Kill one or more processes

    杀死一个或多个进程

    This is the simplest way, but it works.

    这是最简单的方法,但是可以。

什么是活锁? (What is a Livelock?)

There is a variant of deadlock called livelock. This is a situation in which two or more processes continuously change their state in response to changes in the other process(es) without doing any useful work. This is similar to deadlock in that no progress is made but differs in that neither process is blocked or waiting for anything.

死锁有一个变体,称为活锁。 在这种情况下,两个或多个进程响应其他进程的更改而连续更改其状态,而没有做任何有用的工作。 这与死锁相似,因为没有任何进展,但不同之处在于,既没有进程被阻塞也没有等待任何东西。

A human example of livelock would be two people who meet face-to-face in a corridor and each moves aside to let the other pass, but they end up swaying from side to side without making any progress because they always move the same way at the same time.

一个活锁的人类例子是两个人在走廊上面对面相遇,每个人一边走一边让对方通过,但最终却在没有任何进展的情况下左右摇摆,因为他们总是以相同的方式移动同时。

翻译自: https://www.studytonight.com/operating-system/deadlocks

什么是死锁

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值