Zwillingssterns Weltenwald
Published on Zwillingssterns Weltenwald (http://www.zwillingsstern.de)

Startseite > A simple solution to the dining philosophers problem

A simple solution to the dining philosophers problem

The problem

5 Philosophers do nothing but eat and think.

They have a table with 5 chairs, 5 plates and 5 forks.

Each of them eats with two forks.

Ensure that none of them starves.

The solution

First I teach them to always take the left fork first.

Then I smash one of their chairs.

Explanation

Since they can't repair the chair (they think, but they don't build), there are only 4 places left, and so they have one leftover fork which gets passed on, once one finished eating.

Inspired by Willim Stallings' Operating systems: "Use a servant who lets only 4 dine at the same time"

Naturally now they have to either change places or move chairs, so they might still need a servant :)

Werke von Arne Babenhauserheide. Lizensiert, wo nichts anderes steht, unter der GPLv3 or later und weiteren freien Lizenzen.

Diese Seite nutzt Cookies. Und Bilder. Manchmal auch Text. Eins davon muss ich wohl erwähnen — sagen die meisten anderen, und ich habe grade keine Zeit, Rechtstexte dazu zu lesen…


Source URL: http://www.zwillingsstern.de/english/informatics/light/a-solution-to-the-dining-philosophers-problem