Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Real world example of Dining philosophers?

Producer/Consumer and Reader/Writer are easy to think of, but how about Dining philosophers? Under what kind of situation that N processes and N resources will lay on a ring topology and interleaving to each other? I could think of N processes competing for M resources, but in this case each processes may use any two resources.

wiki said Dijkstra used it to simulate computers competing for tape drive peripherials. Does this scenario still exist in modern age?

like image 586
Ray Wu Avatar asked Mar 07 '14 18:03

Ray Wu


2 Answers

I find the problem of executing a transaction between two accounts very similar to the dining philosophers problem. To execute the transaction the thread must lock both accounts to ensure the correct value is debited from one account (first assuring there are available funds) and crediting to another.

The topology is not exactly the round table, but is very close. Imagine 5 accounts at the table. In this analogy, the accounts are the forks. Any two accounts can participate in a transaction. Transactions == philosophers. So in this example the transactions (philosopher) can not only sit at the edge of the table between two accounts (forks), but also on a line cutting across the table, connecting any two accounts (forks).

like image 100
Howard Hinnant Avatar answered Oct 12 '22 23:10

Howard Hinnant


The primary purpose of Dining philosophers and other similar "problems" is not to describe real-world scenarios, rather to give a clean, abstract, even simplified specification for process interactions that can be used as teaching examples on the one hand and building blocks for real software on the other hand.

Specifically, Dining philosophers is a great example to show how livelock and deadlock can occur.

As to a real-world scenario, I do not know about tape drives, but I can imagine a rocket guidance system where rocket wings are the "forks" and the "philosophers" are processes that control pairs of wings to steer the rocket. You do not even have to modify the usual illustrating figure much to switch to this explanation :)

like image 42
xxa Avatar answered Oct 13 '22 00:10

xxa