Search code examples
concurrencydining-philosopher

Deadlock in dining philosophers with channels from Ben Ari?


In Ben Ari's Principles of Concurrent and Distributed Programming (2nd ed.), chapter 8.4, The dining philosophers with channels, they propose a solution which I think might lead to deadlock.enter image description here Suppose a philosopher 3 takes fork 3. The philosopher must then take the 4th fork to eat. But the 4th fork might be taken by the 4th philosopher.

As a generalization, each philosopher might take first the fork 'on his left', resulting in each of them waiting for the other fork to be released, which will never be able to occur.

Am I missing something, or is this solution incomplete?

In the chapter about semaphores, something similar happens, but the authors propose an alternative solution which mitigates the deadlock scenario. For example, one could add a restriction so one philosopher first takes the fork on the opposite side of which the others do, thus avoiding deadlock. I think this might be a possible solution, but I'd like to confirm with someone else here.

Thanks in advance!


Solution

  • Am I missing something, or is this solution incomplete?

    I was definitely not missing anything: I confirmed with the professor teaching this book at my university that this solution does indeed lead to deadlock.