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.
Where the multithreaded magic happens 😄
$> git clone https://github.com/Grsaiago/philosophers.git && cd philosophers && cd philo && make
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 simplymake
-> 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.
$> ./philo <num_of_philos> <time_to_die> <time_to_eat> <time_to_sleep> [num_times_must_eat]
./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
- First and foremost, the multithread chapter of The Linux Programming Interface is a great starter!
- Pthread's man pages (RTFM)
- Codevault's playlist on multithread is a GEM
🧔 Gabriel Saiago