死锁(deadlock)、活锁(livelock)与饿死(starvation)

死锁(deadlock)、活锁(livelock)与饿死(starvation)

发表于 2012-10-22 | 分类:  其他 | 标签:  死锁、 活锁、 饿死

做作业的时候发现,貌似活锁的概念在中英文的世界里是不一样的。

首先是来自wikipedia的解释:

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. This term was defined formally at some time during the 1970s -- an early sighting in the published literature is in Babich's 1979 article on program correctness.[10] 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)。如果事务T1封锁了数据R,事务T2又请求封锁R,于是T2等待。T3也请求封锁R,当T1释放了R上的封锁后,系统首先批准了T3的请求,T2仍然等待。然后T4又请求封锁R,当T3释放了R上的封锁之后,系统又批准了T的请求......T2可能永远等待,这就是活锁。

活锁有一定几率解开。而死锁(deadlock)是无法解开的。

很明显,百度百科解释的活锁其实是饿死(starvation)。

通俗得讲,活锁应该是一系列进程在轮询地等待某个不可能为真的条件为真。活锁的时候进程是不会blocked,这会导致耗尽CPU资源,这是与死锁最明显的区别。

你可能感兴趣的:(java基础)