The classic computer science problem of the Dining Philosophers.
A user defined amount of philosophers dine together at a table. Each of them brings one fork, but needs two to eat, so they have to share with each other. They all have a user defined:
-
Time to eat. - The time it takes for a philosopher to eat. During that time, they will need to hold two forks.
-
Time to sleep. - The time a philosopher will spend sleeping.
-
Time to die. - If a philosopher didn’t start eating "Time to die" milliseconds since the beginning of their last meal or the beginning of the simulation, they die.
This problem aims to illustrate Concurrency, proper use of shared resources and time efficiency.
The problem was solved in two separate ways:
-
Using Threads for synchronous operations between philosophers and Mutexes to ensure proper use of the resources.
-
Using Processes(forks) and Semaphores, for the same reasons, respectively.