This repository contains a program that simulates the classic Dining Philosophers problem. The objective of this project is to implement a program written solely in C without the use of global variables and completely abiding by 42 Network's Norme. This project is an introduction to threads and multithreading.
The Dining Philosophers problem involves a group of philosophers sitting around a circular table with a bowl of rice and a fork between each pair of adjacent philosophers. The philosophers alternate between thinking and eating, and they require two forks to eat their meal.
- Multithreading
- A Unix-like operating system such as Linux or macOS.
- GCC compiler installed.
- Clone this repository:
git clone https://github.com/olebol/philosophers philosophers
- cd into the right directory
cd philosophers
- Run Make to compile the program
make COLOUR=0
or
make COLOUR=1
- Execute the program
./philo amount time_to_die time_to_eat time_to_sleep [times_philosopher_must_eat]
- amount: The number of philosophers and also the number of forks.
- time_to_die: If a philosopher didn’t start eating time_to_die milliseconds since the beginning of their last meal or the beginning of the simulation, they die.
- time_to_eat: The time it takes for a philosopher to eat. During that time, they will need to hold two forks.
- time_to_sleep: The time a philosopher will spend sleeping.
- times_philosopher_must_eat (optional argument): If all philosophers have eaten at least times_philosopher_must_eat times, the simulation stops. If not specified, the simulation stops when a philosopher dies.