From ad8b5f6874d9ee91c3573da72bf1ef298631b206 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Wed, 12 Nov 2025 15:30:33 +0100 Subject: Add README.md --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 README.md (limited to 'README.md') 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 [times_must_eat] +``` -- cgit v1.2.3