- Notifications
You must be signed in to change notification settings - Fork0
Philosophers is a 42 school project simulating multiple philosophers sitting around a table, each with a plate of spaghetti and a fork on their left and right. They share forks with their neighbors to eat. The program uses multithreading and synchronization to prevent deadlocks and starvation. It handles a variable number of philosophers and forks
License
iLucasPires/philo
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This project is about using threads and mutexes to solve theDining Philosophers problem.
The project consists of simulating the behavior of philosophers at a dinner table. Each philosopher has a fork on his left and right. To eat, a philosopher needs both forks. To avoid deadlock, a philosopher must always pick up the fork on his right first, then the fork on his left. When he finishes eating, he puts down both forks so that the other philosophers can eat. The simulation stops when a philosopher dies.
- Clone the repository
git clone https://github.com/iLucasPires/philo.git
- Enter the project folder
cd philo
- Run
make
to compile the project - Run
./philo <number_of_philosophers> <time_to_die> <time_to_eat> <time_to_sleep> [number_of_times_each_philosopher_must_eat]
to execute the program
- The program must not have any memory leaks and data races.
- Each philosopher must be a thread
- Any change of status of a philosopher must be written as follows: timestamp_philosopher_number status
- The status can be: is eating, is sleeping, is thinking, died
- The timestamp is the time in milliseconds since the beginning of the simulation.
- You can’t have more than 10 ms between the death of a philosopher and when it will print its death.
- Each philosopher should eat at least 1 time before dying.
- The simulation stops when a philosopher dies.
- All philosophers must eat at least number_of_times_each_philosopher_must_eat times.
About
Philosophers is a 42 school project simulating multiple philosophers sitting around a table, each with a plate of spaghetti and a fork on their left and right. They share forks with their neighbors to eat. The program uses multithreading and synchronization to prevent deadlocks and starvation. It handles a variable number of philosophers and forks
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.