The dining philosophers problem is invented by E. W. Dijkstra. Imagine that five philosophers who spend their lives just thinking and eating. In the middle of the dining room is a circular table with five chairs. The table has a big plate of spaghetti. However, there are only five forks available, as shown in the following figure. Each philosopher thinks. When he gets hungry, he sits down and picks up the two forks that are closest to him. If a philosopher can pick up both forks, he eats for a while. After a philosopher finishes eating, he puts down the chopsticks and starts to sleep or think.
I tried to make diagram to explain how to solve the problem with threads .