- Thread synchronization
- Mutex handling
- Deadlock and datarace prevention
A number of philosophers sit at a round table. Each one has a fork (or a chopstick in other versions) to their side. The philosophers think so hard that they need to keep eating at a certain rate to avoid dying of overexhaustion. Sadly, in order to eat, the philosopher must use two forks. How will the philosophers pace their eating and share their forks in order to avoid dying?
This program runs a simulation of philosophers in the described situation. The philosophers eat 🍽️, sleep 💤 and think 💭 and these actions are printed out as timestamped logs. The simulation ends if a philosopher dies.
Clone the project using the following command
git clone https://github.com/jelloster/philosophers.git
- Navigate into the project folder
cd philosophers
- Compile the project with make
make
- Run the program and give it the following input:
./philo <num of philos> <time to die (ms)> <time to eat (ms)> <time to sleep (ms)> <(optional) max meals per philo>
Example:
./philo 4 210 100 100
This translates to:
- 4 Philosophers
- Time to die : 210 ms
- Time to eat : 100 ms
- Time to sleep : 100 ms

