diff options
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..8fe9065 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# Philosophers Project +A concurrency challenge in C, solved as part of the Core Curriculum at 42 Heilbronn. + +## The challenge +A number of philosophers sits around a table with a huge bowl of spaghetti in the middle. +Each philosopher eats, sleeps, thinks and repeats this cycle until one of them starves. +The same number of forks is laying on the table, each fork between two philosophers. +In order to eat, a philosopher needs two forks. +Every fork can only be used by one philosopher at a time. + +After each philosopher has eaten a specified amount of times or if one philosopher dies, the simulation ends. + +## Implementation +Each philosopher is realized as a thread. While the simulation is running, each philosopher tries to take the forks next to them. +If they have both forks, they start eating. After they're done, they release both forks and go to sleep. Each fork as well as other shared data is protected by a mutex in order to avoid race conditions. +To avoid deadlocks, even numbered philosophers take the right fork first, while odd numbered philosophers take the left one first. + +Every change of state is printed to stdout. + +## How to run +```bash +# Clone the repository +git clone https://github.com/dkaisr/Philosophers.git +cd Philosophers/philo + +# Compile +make + +# Run +# ttd: Time to die in ms, tte: Time to eat in ms, tts: Time to sleep in ms +./philo <nbr_of_philos> <ttd> <tte> <tts> [times_must_eat] +``` |
