This project has been created as part of the 42 curriculum by rpinheir
The Dining Philosophers Problem is a classic concurrency challenge. This project teaches thread management, mutex synchronization, and deadlock prevention in C.
Each philosopher is a thread. Each fork is a mutex. Philosophers must pick up two forks to eat, then sleep, then think. If a philosopher doesn't eat within a given time, they die. The simulation stops when a philosopher dies or when all have eaten enough.
Build from the philo/ directory:
cd philo && makeRun with the following arguments:
./philo number_of_philosophers time_to_die time_to_eat time_to_sleep [max_meals]
| Argument | Description |
|---|---|
number_of_philosophers |
Number of philosophers and forks |
time_to_die |
Time in ms before a philosopher dies without eating |
time_to_eat |
Time in ms a philosopher spends eating (holding 2 forks) |
time_to_sleep |
Time in ms a philosopher spends sleeping |
max_meals |
(optional) Simulation stops when all philosophers have eaten this many times |
./philo 5 800 200 200 # No one should die
./philo 1 800 200 200 # One philosopher, dies at 800ms
./philo 4 310 200 100 # A philosopher dies at 310ms
./philo 5 800 200 200 7 # Stops when everyone has eaten 7 timesClaude Code was used as a debugging and review assistant throughout the project. Specifically:
- Identifying data races and mutex inconsistencies
- Adding doxygen documentation comments
- README formatting and structure
All code was written by me.