For this project, the assignment is :
In this project, you will learn the basics of threading a process. You will see how to create threads and you will discover mutexes.
We must create an algorithm that keeps the philosophers alive as far as possible. The programs must take several parameters:
number_of_philosophers
: the number of philosophers around the table
time_to_die
: a number representing the time in milliseconds a philosopher has to live after a meal. If a philosopher hasn’t started eating time_to_die milliseconds after the beginning of his last meal or the beginning of the simulation, he will die.
time_to_eat
: a number representing the time in milliseconds a philosopher takes to finish his meal. During that time, the philosopher keeps his two forks in hand.
time_to_sleep
: the time in milliseconds that a philosopher spends sleeping.
number_of_times_each_philosopher_must_eat
: an optional argument that allows the program to stop if all the philosophers have eaten at least that many times. If this argument is not specified, the simulation carries on unless a philosopher dies.
In order to compile :
make
Execution :
./philo <number_of_philosophers> <time_to_die> <time_to_eat> <time_to_sleep> [number_of_times_each_philo_must_eat]
Exemple =
./philo 4 800 200 200 3