There is a large bowl of spaghetti in the middle of the table.
The philosophers alternatively eat, think, or sleep.
There are as many forks as philosophers. There is one fork between each pair of philosophers.
A philosopher takes their right and their left forks to eat, one in each hand.
When a philosopher has finished eating, they put their forks back on the table and start sleeping.
Once awake, they start thinking again.
The simulation stops when a philosopher dies of starvation.
Arguments:
- The number of philosophers (and forks).
- (in milliseconds): If a philosopher didn’t start eating at this time since the beginning of their last meal or the beginning of the simulation, they die.
- (in milliseconds): The time it takes for a philosopher to eat. During that time, they will need to hold two forks.
- (in milliseconds): The time a philosopher will spend sleeping.
- (optional argument): If all philosophers have eaten at least that number of times, the simulation stops.
Each philosopher must be a thread.
Use mutex for forks and to use printf.
You can't have more than 10ms between the death of a philosopher and the moment you print their death.
Try not to kill your poor philosophers.
Compile and execute the progra in philo folder
make run
They have no states in memory but the number of available forks is represented by a semaphore.
Each philosopher should be a process. But the main process should not be a philosopher.
Compile and execute the program in philo_bonus folder
make run