哲学家死锁问题

取决于具体实现,拿两根筷子,一般说的是先拿一根,再拿第二根,那毫无疑问是会死锁的,只要筷子数量不超过人数就行了。如果筷子数量超过人数,但不到人数两倍,不会死锁,但会降低效率。
■网友
每次看到这个问题我就想问,你们哲学家真恶心,和别人一起吃饭还共用筷子
■网友
除非拿筷子是原子操作,能够保证一次性拿到两根筷子。否则进程是顺序执行的,先拿起一根筷子,再拿起另一根筷子,这之间就可能导致进程间的竞争死锁
■网友
我也觉得是会死锁的。因为答案的代码里是一条一条筷子拿的,并不是一次拿两条筷子。代码如下:class ChopstickQueue extends LinkedBlockingQueue\u0026lt;Chopstick\u0026gt;{}private ChopstickQueue bin = new ChopstickQueue(); 【哲学家死锁问题】 哲学家死锁问题

但答案最后说好像是不会死锁,难道是我英文太差了?We use ChopstickQueue to create the ChopstickBin, so it gains all ofLinkedBlockingQueue’s control logic. Instead of picking up the left and rightchopsticks, philosophers take them from a common bin, an activity we suspendwhen too few chopsticks remain. The results are the same, with the flaw that anequal number of chopsticks and philosophers can quickly deadlock, but a singleextra chopstick prevents this
■网友
Dining Philosophers Problem虽然是 C 语言实现的。


    推荐阅读