philosophers is a project centered on learning the basics of process threading and mutexes.
it is a variation on the famous dining philosophers problem.
here are some of the sources that i used:
• threads, mutexes and concurrent programming in c
• the dining philosophers problem
• a very handy philosophers visualizer by nfukada
this problem is a common challenge in computer science.
it is often used to show difficulties in designing algorithms that run at the same time and in coordinating processes.
it was first introduced in 1965 by edsger dijkstra as part of a student exam and was originally explained using computers competing for access to tape drives.
here's how our subject articulates this problem:
• one or more philosophers sit at a round table;
• there is a large bowl of spaghetti in the middle of the table;
• the spaghetti can only be eaten with two forks;
• there are only as many forks as there are philosophers;
• each philosopher successively eats, sleeps and thinks;
• if a philosopher hasn't eaten in a certain timeframe, he will die of starvation;
• philosophers cannot communicate with each other.
-
clone this repository:
git@github.com:idleira/philosophers.git philosophers && cd philosophers/philo
; -
use
make
to compile the project; -
run the program with
./philo (number_of_philosophers) (time_to_die) (time_to_eat) (time_to_sleep)
-
you can add an optional
[number_of_times_each_philosopher_must_eat]
at the end too; -
for example:
./philo 5 800 200 200
or./philo 5 800 200 200 7
-
-
to clean up:
• use
make clean
to remove .o files;• use
make fclean
to clean up the project directory by removing all generated files.