Implementation on Dining Philosophers problem on C++
A certain number of philosophers spend their lives alternating between thinking and eating. They are seated around a circular table. There is a chopstick placed between each pair of neighboring philosophers. Each philosopher has access to the chopsticks at her left and right. In order to eat, a philosopher must be in possession of both chopsticks. A philosopher may only pick up one chopstick at a time. Each philosopher attempts to pick up the left chopstick first and then the right chopstick. When done eating, a philosopher puts both chopsticks back down on the table and begins thinking. Since the philosophers are sharing chopsticks, it is not possible for all of them to be eating at the same time.
This was originally formulated in 1965 by Edsger Dijkstra as a student exam exercise.
- The philosopher enters into a waiting state when neighbors are eating
- When its neighbors are done, go for the chopsticks
- Its neighbors can't enter into the waiting state if there is a neighbor already waiting
Tests are done using googletests