Overview
The goal of this project is to solve the dining philosophers problem by using multi-threading.
Each philosophers are represented by threads and are using shared memory which are the forks. In order to avoid anyconflicts regarding accessto to this common ressource, mutexes are used. Mutexes provide mutual exclusion over shared resources, as they can be locked andunlocked. Locking a ressource allows to deny access to it to other threads at the same time. Thus this could avoid data races but could create deadlocks.
The program should take the following arguments: number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]
- number_of_philosophers: is the number of philosophers and also the number of forks.
- time_to_die: is in milliseconds, if a philosopher doesn’t start eating ’time_to_die’ milliseconds after starting their last meal or the beginning of the simulation, it dies. time_to_eat: is in milliseconds and is the time it takes for a philosopher to eat. During that time they will need to keep the two forks.
- time_to_sleep: is in milliseconds and is the time the philosopher will spend sleeping.
- number_of_times_each_philosopher_must_eat: argument is optional, if all philosophers eat at least ’number_of_times_each_philosopher_must_eat’ the simulation will stop. If not specified, the simulation will stop only at the death of a philosopher.
Open a terminal and run following command:
git clone <repository url>
Go to the created repository and run following command:
make
To start run the following command (the last argument is optionnal):
./philo number_of_philosophers time_to_die time_to_eat time_to_sleep time_to_eat
Some test cases are provided as well as the expected behavior in test.txt
Hit CTRL + C to kill the process