死锁和活锁有什么区别? [英] What's the difference between deadlock and livelock?

查看:97
本文介绍了死锁和活锁有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以用示例(代码)解释死锁活锁有什么区别吗?

Can somebody please explain with examples (of code) what is the difference between deadlock and livelock?

推荐答案

来自 http://en. wikipedia.org/wiki/死锁:

在并发计算中,死锁是一种状态,其中一组动作的每个成员都在等待其他成员释放锁

In concurrent computing, a deadlock is a state in which each member of a group of actions, is waiting for some other member to release a lock

活动锁类似于死锁, 除了 活锁中涉及的过程 关于一个不断变化 另一个,没有进展.活锁是 资源匮乏的特殊情况; 一般定义只说明 一个特定的过程不是 进步.

A livelock is similar to a deadlock, except that the states of the processes involved in the livelock constantly change with regard to one another, none progressing. Livelock is a special case of resource starvation; the general definition only states that a specific process is not progressing.

一个真实的例子 当两个人见面时发生活锁 在狭窄的走廊里,每个人都尝试 放在一边让自己有礼貌 另一遍,但他们最终 左右摇摆而没有 之所以取得进展,是因为他们俩 反复以相同的方式在 同时.

A real-world example of livelock occurs when two people meet in a narrow corridor, and each tries to be polite by moving aside to let the other pass, but they end up swaying from side to side without making any progress because they both repeatedly move the same way at the same time.

Livelock存在以下风险 一些算法可以检测并 从僵局中恢复.如果超过 一个过程采取行动,陷入僵局 检测算法可以重复 触发.这可以通过以下方式避免 确保只有一个流程(选择 随机或优先)采取行动.

Livelock is a risk with some algorithms that detect and recover from deadlock. If more than one process takes action, the deadlock detection algorithm can be repeatedly triggered. This can be avoided by ensuring that only one process (chosen randomly or by priority) takes action.

这篇关于死锁和活锁有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆