...
/The Dining Philosophers Benchmark
The Dining Philosophers Benchmark
Understand the dining philosophers' problem and asynchronous solutions in Python.
Dining philosophers problem and solution
The faculty of the College of Philosophy in an old seaside resort city (on the Atlantic coast of the US) has a long-standing tradition of dining together every Sunday night. The food is catered from Mo’s Deli, but is always—always—a heaping bowl of spaghetti. No one can remember why, but Mo’s a great chef, and each week’s spaghetti is a unique experience.
Scenario
The philosophy department is small, having five tenured faculty members. They’re also impoverished and can only afford five forks. Because the dining philosophers each require two forks to enjoy their pasta, they sit around a circular table, so each philosopher has access to two nearby forks.
This requirement for two forks to eat leads to an interesting resource contention problem, shown in the following diagram:
Ideally, a philosopher, say Philosopher 4
, the department chairperson, and an Ontologist, will acquire the two closest forks, Fork 4
and Fork 0
, required to eat. Once they’ve eaten, they release the forks so they can spend some time on philosophy.
The deadlock problem
There’s a problem waiting to be solved. If each philosopher is right-handed, they will reach out, grab the fork on their right, and—unable to grab ...