Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Logo

I never thought philosophy would be so deadly
Project philosophers of 42 school

📌 Index

✨ What is philosophers?

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.

Screen Shot 2024-03-07 at 1 41 44 PM

🕹 Rules

💀 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.

🛠 Set the params

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).

💻 Usage

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.

📖 Examples

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 100

Should one philosopher die. Output should be:

Screen Shot 2024-03-07 at 5 37 21 PM

Execute the bonus whith the arguments in the terminal.

./philo_bonus 4 410 200 100 1

Output should be:

Screen Shot 2024-03-07 at 5 42 35 PM

About

I never thought philosophy would be so deadly

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages