Vinicius Oliveira

Philosophers

Dijkstra's dining philosophers simulation.

École 422022
CUnixThreads

Introductory project on threads in C for École 42, inspired by the Dining Philosophers problem by Edsger Dijkstra.

The problem consists of simulating a dinner with an arbitrary number of philosophers sitting around a round table. Each philosopher has a plate of spaghetti in front of them, and there is a fork between each pair of plates. The philosophers alternate between three states: thinking, eating, and sleeping. To eat, a philosopher needs to pick up the two forks next to them. If a fork is occupied, the philosopher must wait until both are available. The goal is to avoid deadlock or starvation.

The simulation can be configured with different parameters, such as the number of philosophers, the maximum lifespan of each philosopher, the time it takes for each philosopher to eat and sleep, as well as the maximum number of meals each philosopher can have. The simulation ends when all philosophers complete the maximum number of meals or when a philosopher dies.