- Global variables are forbidden!
- Your program(s) must accept the following arguments:
◦
number_of_philosophers (int between 1 and 200):
is the number of philosophers, but also the number of forks.◦
time_to_die (in milliseconds):
if a philosopher doesn't start eating within time_to_die milliseconds from the start of their last meal or from the beginning of the simulation, they will die.◦
time_to_eat (in milliseconds):
is the time a philosopher has to eat. During this time, they will have the forks occupied.◦
time_to_sleep (in milliseconds):
is the time a philosopher has to sleep.◦
number_of_times_each_philosopher_must_eat (optional argument):
if all philosophers eat at least number_of_times_each_philosopher_must_eat times, the simulation will stop. If not specified, the simulation will stop with the death of a philosopher.- Each philosopher will be assigned a number from 1 to number_of_philosophers.
- Philosopher number 1 will sit next to philosopher number number_of_philosophers. Any other philosopher number N will sit between philosopher number N - 1 and philosopher number N + 1.
Any change in the state of a philosopher follow this format:
◦ timestamp_in_ms X has taken a fork
◦ timestamp_in_ms X is eating
◦ timestamp_in_ms X is sleeping
◦ timestamp_in_ms X is thinking
◦ timestamp_in_ms X died
make
Run the program with the following arguments:
./philo <number_of_philosophers> <time_to_die> <time_to_eat> <time_to_sleep> [number_of_times_each_philo_must_eat]
example(no philo dies):
./philo 4 410 200 200
example(one philo dies):
./philo 4 310 200 100
example(with opcional parameter):
./philo 5 800 200 200 7
If the inputs are correct, the software will document each philosopher's actions until one passes away or until they've all reached the specified number_of_times_each_philo_must_eat, if that parameter is given.