Skip to content

My C implementation of the philosopher's dinner, a parallel nightmare

Notifications You must be signed in to change notification settings

Grsaiago/philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 

Repository files navigation

42 Cursus' Philosophers

Think, Spaghetti, Sleep, repeat. This 42rio project is about learning how threads, shared memory, mutexes, and deadlocks work by precisely timing a group of philosophers on when to pick up forks and eat spaghetti without dying from hunger.

Install

Mandatory

Where the multithreaded magic happens 😄

$> git clone https://github.com/Grsaiago/philosophers.git && cd philosophers && cd philo && make

Bonus

The magic still happens, but this time with ✨UNIX Semaphores✨

$> git clone https://github.com/Grsaiago/philosophers.git && cd philosophers && cd philo_bonus && make

make supports the following flags for both mandatory and bonus part.

  • all or simply make -> Compiles everything, creates a debug dir, and gets the program ready to go!
  • make clean -> removes the executable and the debug dir.
  • make re -> removes the executable, the debug dir and recompiles everything.

Usage

$> ./philo <num_of_philos> <time_to_die> <time_to_eat> <time_to_sleep> [num_times_must_eat]

Examples

./philo 1 800 200 200 // Not enough forks, one philo tries to eat but dies out 😥
./philo 5 800 200 200 // No one dies
./philo 5 800 200 200 7 // Simulation stops when all philosophers eat 7 times
./philo 4 410 200 200 // No one dies
./philo 4 310 200 100 // One philosopher dies
./philo 4 500 200 1.2 // Invalid arguments
./philo 4 0 200 200 // Invalid arguments
./philo 4 -500 200 200 // Invalid arguments
./philo 4 2147483647 200 200 // No one dies
./philo 4 200 210 200 // One philosopher dies

Tips for the project

✨Author✨

🧔 Gabriel Saiago

About

My C implementation of the philosopher's dinner, a parallel nightmare

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published