2023-04-19 00:31:43 +02:00
|
|
|
# dining-philosophers
|
|
|
|
|
2023-04-19 01:28:50 +02:00
|
|
|
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
|
2023-04-19 01:40:22 +02:00
|
|
|
on each side that they are supposed to share with their neighbors
|
2023-04-19 01:28:50 +02:00
|
|
|
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.
|
|
|
|
|
|
|
|
[https://en.wikipedia.org/wiki/Dining_philosophers_problem](https://en.wikipedia.org/wiki/Dining_philosophers_problem)
|