This is a project from the third circle of the 42 cursus. It introduces to two major problems that happen in operating systems which are :
- There is n philosophers sitting around a table, there are as many forks as them and a bowl of spaghetti
- Philosophers can be in 3 states : eating, sleeping or thinking state, each one can eat only if he has two forks.
- Philosophers are threads (processes for the bonus part), forks are mutexes (semaphores for the bonus part).
- Make a program that synchronizes the philosophers ,avoid deadlocks and starvation and print each action that the philosopher does in the current time in ms.
- Number of philosophers
- Time to die (If a philosopher didn’t start eating time_to_die miliseconds since the beginning of their last meal they die)
- Time to eat (The time that they should spend eating (using forks))
- Time to sleep (The time that they should spend sleeping)
- (optional) Number of meals (If all philosophers ate n meals, the simulation stops)
- Enter the folder 'philo' (threads and mutexes) or philo_bonus (processes and semaphores)
- Type make for the compilation process
- Execute with the desired arguments
- ./philo 5 800 200 200 or ./philo_bonus 5 800 200 200 (the simulation will never end)
- ./philo 2 400 150 150 7 or ./philo_bonus 2 400 150 150 7 (the simulation will stop when all philosophers eat 7 times)
- ./philo 4 310 200 100 or ./philo_bonus 4 310 200 100 (a philosopher will die)
- Functionning of threads, mutexes, semaphores
- Threads synchronization
- Processes synchronization
- Unix logic
- Data race management