A commented example of solving the dining philosophers multithreading problem.
Description of the dining philosophers problem.
The dinner philosophers problem consists of a round table where N number of philosophers are seated, every philosopher has a fork on each side that they are supposed to share with their neighbors to eat a spaghetti that can only eated by the usage of two forks.
The problem consists on achieving the table to be able to continuously eat without getting stuck in a deadlock without the chance of philosophers to talk between themselves.
Description of the solution.
For the solution I inspired on the Dijkstra's solution but using the OOP nature of C++ to make it more readable and near to the natural language.
The code is commented in its tricky parts in order to make the solution easier to understand.