Communicating Sequential Processes

C.A.R. (Tony) Hoare
Prentice-Hall, 1985

2 Concurrency

2.5 Example: The Dining Philosophers

In ancient times, a wealthy philanthropist endowed a College to entertain five eminent philosophers. Each philosopher had a room in which he could engage in his professional activity of thinking; there was also a common dining room, furnished with a circular table, surrounded by five chairs. The name of the philosophers were PHIL0, PHIL1, PHIL2, PHIL3, PHIL4, and they were disposed in this order anticlockwise around the table. To the left of each philosopher there was laid a golden fork, and in the centre stood a large bowl of spaghetti, which was constantly replenished.

A philosopher was expected to spend most of his time thinking; but when he felt hungry, he went to the dining room, sat down in his own chair, picked up his own fork on his left, and plunged it into the spaghetti. But such is the tangled nature of spaghetti that a second fork is required to carry it to the mouth. The philosopher therefore had also to pick up the fork on his right. When he was finished he would put down both his forks, get up from his chair, and continue thinking. Of course a fork can be used by only one philosopher at a time. If the other philosopher wants it, he just has to wait until the fork is available again. [...]

2.5.3 Deadlock!

When a mathematical model had been constructed, it revealed a serious danger. Suppose all the philosophers get hungry at about the same time; they all sit down; they all pick up their own forks; and they all reach out for the other fork—which isn't there. In this undignified situation, they will all inevitably starve. [...]

The edifying tale of the dining philosophers is due to Edsger W. Dijkstra.


Software
Marc Girod