This project simulates the classic "Dining Philosophers" problem to explore concurrency issues such as deadlock and starvation. The simulation involves philosophers sitting at a round table, eating spaghetti, thinking, and sleeping. Philosophers need two forks to eat, which they take from their left and right. The simulation stops when a philosopher dies of starvation or when all philosophers have eaten a specified number of times.
- Concurrency Management: Implement philosophers first as threads, then as processes to simulate concurrent actions.
- Fork Management: Use mutexes with threads, and semaphores with processes to manage fork usage and avoid conflicts.
- State Logging: Log the state changes of each philosopher with precise timestamps.
- Death Detection: Detect and log philosopher death due to starvation within a specified time frame.
The program takes the following command-line arguments:
number_of_philosophers
: The number of philosophers and forks.time_to_die
: Time in milliseconds before a philosopher dies if they don't start eating.time_to_eat
: Time in milliseconds a philosopher spends eating.time_to_sleep
: Time in milliseconds a philosopher spends sleeping.[number_of_times_each_philosopher_must_eat]
(optional): The simulation stops when all philosophers have eaten at least this many times. If not specified, the simulation stops when a philosopher dies.
- Clone the repository:
git clone <repository-url>
- Compile the project (philosophers as threads):
make
- Run the project (philosophers as threads):
./philo number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]
- Compile the project (philosophers as processes):
make bonus
- Run the project (philosophers as processes):
./philo_bonus number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]
- The 42 School for providing the project specifications and environment.