A simple solution to the dining philosophers problem

  • warning: call_user_func_array() expects parameter 1 to be a valid callback, function '_poll_menu_access' not found or invalid function name in /www/htdocs/w0062791/arnebab/includes/menu.inc on line 455.
  • warning: call_user_func_array() expects parameter 1 to be a valid callback, function '_poll_menu_access' not found or invalid function name in /www/htdocs/w0062791/arnebab/includes/menu.inc on line 455.

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 :)

Inhalt abgleichen
Willkommen im Weltenwald!
((λ()'Dr.ArneBab))



Draketo neu: Beiträge

Draketo neu: Kommentare