8

我读到 Io 语言Futures可以自动检测死锁。我对此一无所知,并且看过一些语法。Io 语言如何检测死锁?

4

2 回答 2

7

每个未来都知道它正在等待哪个演员,每个演员都知道它正在等待哪个未来(如果有的话),所以 Io 只是遍历这个链以查看当前演员是否在其中。如果是这样,就会出现僵局。如果没有,则没有。

于 2010-12-28T16:05:12.957 回答
7

Io 遇到死锁时会抛出异常。

参考:我相信Steve Dekortelang.lightweight上的帖子。留言贴在下面:

Io 具有异步消息和期货形式的延续。例子:

aFuture = obj @foo

// the @ means "perform message foo asynchronously"
// that is, in a light weight thread owned by obj
// The aFuture's value ivar is set with the result

result = aFuture value

// This causes the current light weight thread to pause
// until the aFuture's vale is set.
// So this is effectively a continuation.
// another option is:

obj @(foo) sendResultTo(target, "foobar")

// which is more like the callcc style

这种使用方式的有趣之处在于,似乎没有人觉得它难以理解。此外,Io 使用期货来进行自动死锁检测。当发生死锁时,它会引发异常而不是允许它。

注意。上面的帖子是 2003 年的,所以有一些变化。请参阅最新的在线Concurrency文档以获取最新信息。


更新- 从在线文档中它确实说:

自动死锁检测

使用futures的一个优点是,当future需要等待时,它将检查是否暂停等待结果会导致死锁,如果是,避免死锁并引发异常。它通过遍历已连接的期货列表来执行此检查。

于 2010-11-08T12:54:18.367 回答