本帖最后由 highgear 于 2011-10-23 11:33 编辑
好吧,要文明些。
我也知道刘前辈不敢PK, 他的这些帖子无非是转移注意力,把PK变成无聊的口水仗而已。
既然老叶,匠人都加入进来,那我还是把哲学家就餐是否存在死锁这个 ... 低速cpu... 问题讲一讲,只讲一次,不再重复。如果老刘还像上次那个"LED数码管动态扫描"里的表现那样,那么,就不能责怪我给老刘冠以"低速cpu"的称号。
首先, 要证明 xx不存在这个命题,举出一千亿个不存在的例子也不能证明这个命题成立,而只要有一个例子证明存在,这个命题就会被推翻,这是一个简单到近乎弱智,啊不对,是低速cpu的逻辑。
其实,哲学家就餐本来就是为了解决死锁问题而提出的:
http://en.wikipedia.org/wiki/Dining_philosophers_problem
The problem was designed to illustrate the problem of avoiding deadlock, a system state in which no progress is possible.
One idea is to instruct each philosopher to behave as follows:
- think until the left fork is available; when it is, pick it up;
- think until the right fork is available; when it is, pick it up
- eat
- put the left fork down
- put the right fork down
- repeat from the start
This solution is incorrect: it allows the system to reach deadlock, namely, the state in which each philosopher has picked up the fork to the left, waiting for the fork to the right to be put down.
Resource starvation might also occur independently of deadlock if a particular philosopher is unable to acquire both forks because of a timing problem.
上面的内容讲的清清楚楚,明明白白。这种解法(指上述就餐过程)不正确:它让系统达到死锁。
另外的一个简单证明就是,我们可以把就餐问题简化为两个固执的哲学家A, B 与两把叉子 a, b. 当A,B 同时拿起a, b后, A 在等待b, B在等待a, 熬啊,熬啊,终于熬出了阿香婆..., 啊不,什么也没熬出,AB都饿死了, 这是一个典型的死锁。由此,可以推及 三人,四人,五人等等。
至于什么奇偶问题,更不值一提。很简单,如果存在奇数问题,以这些大科学家的严谨, 题目就会是 奇数个哲学家就餐问题。
。
|