Skip to content

Classic dining philosophers problem resolved using multithreading with mutex (mandatory) and multiprocessing with semafores (bonus)

License

Notifications You must be signed in to change notification settings

iker-gonzalez/philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🍝 Philosophers 🤓

Development repo for 42cursus' philosophers project
For further information about 42cursus and its projects, please refer to 42cursus repo.

GitHub code size in bytes Number of lines of code Code language count GitHub top language GitHub last commit


🗣️ About

In this project, you will learn the basics of threading a process. You will learn how to make threads. You will discover the mutex.

42's take on the classic Dining philosophers problem. The mandatory part was done using the phtread API to execute n numbers of threads at once that eat, sleep, then start eating again. Mutex was used to manage the limited resources available. Given the right parameters, philosophers keep repeating their cycle virtually forever, unless a maximum number of times each philosopher must eat before the simulation ends is given. Examples:

n_philosophers  time_before_death time_eat  time_sleep  [time_eats]
4 410 200 200
5 800 200 200 5

For detailed information, refer to the subject of this project

🛠️ Usage

Clone the repo and open the corresponding folder.

Compile the program

make

Execute program with parameters: n_philosophers time_before_death time_eat time_sleep [numbers_of_eats] (last parameter is optional)

./philo 4 410 200 200 1

Expected output:

0 1 has taken a fork
0 1 has taken a fork
0 1 is eating
0 3 has taken a fork
0 3 has taken a fork
0 3 is eating
200 3 is sleeping
200 1 is sleeping
200 2 has taken a fork
200 2 has taken a fork
200 4 has taken a fork
200 4 has taken a fork
200 4 is eating
200 2 is eating

About

Classic dining philosophers problem resolved using multithreading with mutex (mandatory) and multiprocessing with semafores (bonus)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published