Contents
What is the problem of the dining philosophers?
The dining philosophers problem illustrates non-composability of low-level synchronization primitives like semaphores. It is a modification of a problem posed by Edsger Dijkstra. Five philosophers, Aristotle, Kant, Spinoza, Marx, and Russell (the tasks) spend their time thinking and eating spaghetti.
What does the input mean in dining philosophers?
The input to the program is the number of philosophers to be seated around the table. Output shows the various stages that each philosopher passes through within a certain time. A philosopher can be in anyone of the three stages at a time: thinking, eating or finished eating.
How many forks does a philosopher need to eat?
Every Philosopher needs two forks in order to eat. Every Philosopher may pick up the forks on the left or right but only one fork at once. Philosophers only eat when they had two forks. We have to design such a protocol i.e. pre and post protocol which ensures that a philosopher only eats if he or she had two forms.
Who are the five philosophers that eat spaghetti?
Five philosophers, Aristotle, Kant, Spinoza, Marx, and Russell (the tasks) spend their time thinking and eating spaghetti. They eat at a round table with five individual seats.
How many deadlocks are there in dining philosophers?
There exist two deadlock states when all five philosophers are sitting at the table holding one fork each. One deadlock state is when each philosopher has grabbed the fork left of him, and another is when each has the fork on his right. There are many solutions of the problem, program at least one, and explain how the deadlock is prevented.
How to model the forks of a philosopher?
The following solution uses an array of mutexesin order to model the forks. The forks used by a philosopher compose a subset in the array. When the the philosopher seizes his forks from the subset the array object prevents deadlocking since it is an atomic operation.
What happens when a philosopher cannot grab both forks?
When a philosopher cannot grab both forks it sits and waits. Eating takes random time, then the philosopher puts the forks down and leaves the dining room. After spending some random time thinking about the nature of the universe, he again becomes hungry, and the circle repeats itself.