I never thought philosophy would be so deadly
Project philosophers of 42 school
This project is a training to multi-threads/multi-process programming with the use of mutex and semaphore. It contains N different proccess or threads simulating the famous Dining Philosophers problem, all with the same basic rules. Optimization is a must to ensure the survival of our philosophers.
| 💀 | The philosophers must never be starving, they need to eat. |
| ❌ | The simulation stops when a philosopher dies. |
| ⏳ | No more than 10 ms between the death and print its death. |
| 🖨 | The status printed should not be messed with another philosopher’s status. |
| 🍽 | While eating, they are not thinking or sleeping. |
| 😴 | While sleeping, they are not eating or thinking. |
| 🤔 | While thinking, they are not eating or sleeping. |
| 🍴 🍴 | Philosopher must eat with two forks, one for each hand. |
| 💬 | Philosophers don’t speak with each other. |
| 💭 | Philosophers don’t know when another philosopher is about to die. |
| 🍽→🍴🍴→😴 | Each time a philosopher has finished eating, he will drop his forks and start sleeping. |
| 😴→🤔 | When a philosopher is done sleeping, he will start thinking. |
| 🤔→🍴🍴→🍽 | When a philosopher is done thinking, he will take 2 forks to eating. |
number_of_philosophers |
number of philosophers (process / threads). |
time_to_die |
Miliseconds after starting his last eating or start de simulation to die. |
time_to_eat |
Milliseconds will spend to eating after take the 2 forks. |
time_to_sleep |
Milliseconds will spend to sleeping. |
number_of_times_each_philosopher_must_eat |
[optional]. If all ate at least number_of_times_each_philosopher_must_eat, simulation finish. If not specified, simulation continue till someone die. |
number_of_philosophers |
number of philosophers (process / threads). |
cd philo && make to compile the executable with threads / mutex.
cd philo_bonus && make to compile the executable with process / semaphores.
make clean remove .o files.
make fclean remove .o files and .a files and executable.
The arguments of the executable should be:
number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]Execute whith the arguments in the terminal.
./philo 4 310 200 100Should one philosopher die. Output should be:
Execute the bonus whith the arguments in the terminal.
./philo_bonus 4 410 200 100 1Output should be:
