While I was looking at the JPF examples, I have found a well known problem in concurrency. It was firstly propounded by Edsger Wybe Dijkstra as a problem where five computers competed for access to five shared tape drive peripherals. Later on, the problem was narrated by Tony Hoare as the dining philosophers problem.
There is a group of philosophe
rs ( usually 5 and greater than 2) who eat together at a round table. There are forks placed between the philosophers. Philosophers spend their time either thinking or eating. In order to eat, a philosopher must pick up exactly two forks, one on his immediate left, and the other on his immediate right. When he is done eating, he will put his forks down so that his neighbors may use them, and he thinks again.
The challenge in the dining philosophers problem is to design a method so that the philosophers do not deadlock (i.e. every philosopher has a fork), and so that no philosopher starves (i.e. when a philosopher is hungry, he/she eventually gets the forks). Additionally, the method should try to be as efficient as possible — in other words, the solution should try to minimize the time that philosophers spent waiting to eat.
Now how do we represent these into multi-threading?
Philosophers = Threads
Food = Resources
Forks = Semaphore/Locks
For the ones who do not know what semaphore is : Semaphore is basically a permit or a key to access the resources ( of course in computer science). Look here for another meaning of it.
There are several answers for this problem.
rs ( usually 5 and greater than 2) who eat together at a round table. There are forks placed between the philosophers. Philosophers spend their time either thinking or eating. In order to eat, a philosopher must pick up exactly two forks, one on his immediate left, and the other on his immediate right. When he is done eating, he will put his forks down so that his neighbors may use them, and he thinks again.