# Philosophers Project A concurrency challenge in C, solved as part of the Core Curriculum at 42 Heilbronn. ## The challenge A number of philosophers sits around a table with a huge bowl of spaghetti in the middle. Each philosopher eats, sleeps, thinks and repeats this cycle until one of them starves. The same number of forks is laying on the table, each fork between two philosophers. In order to eat, a philosopher needs two forks. Every fork can only be used by one philosopher at a time. After each philosopher has eaten a specified amount of times or if one philosopher dies, the simulation ends. ## Implementation Each philosopher is realized as a thread. While the simulation is running, each philosopher tries to take the forks next to them. If they have both forks, they start eating. After they're done, they release both forks and go to sleep. Each fork as well as other shared data is protected by a mutex in order to avoid race conditions. To avoid deadlocks, even numbered philosophers take the right fork first, while odd numbered philosophers take the left one first. Every change of state is printed to stdout. ## How to run ```bash # Clone the repository git clone https://github.com/dkaisr/Philosophers.git cd Philosophers/philo # Compile make # Run # ttd: Time to die in ms, tte: Time to eat in ms, tts: Time to sleep in ms ./philo [times_must_eat] ```