The philosophers project is a classic exercise in concurrent programming. Inspired by Dijkstra's dining philosophers problem, it involves creating a simulation where philosophers alternatively eat, think, and sleep. The challenge lies in managing shared resources (forks) and ensuring no philosopher starves or causes a deadlock.
This is an overview of the main components located in the "sources" directory of the philosophers project.
To use the philosophers program, compile it using the provided Makefile. Then, run the program with the required arguments:
./philo number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]
The philosophers project offers the following features:
- Concurrent Simulation: Simulates multiple philosophers engaging in eating, thinking, and sleeping concurrently.
- Resource Management: Uses mutexes to manage access to shared forks, preventing deadlocks and ensuring fairness.
- Customizable Parameters: Allows the user to specify the number of philosophers, and various time parameters to tailor the simulation.
- Error Handling: Properly handles errors and provides informative messages, ensuring robustness.
To see the philosophers simulation in action with 5 philosophers, where each philosopher dies if they do not eat within 800ms, takes 200ms to eat, and sleeps for 100ms:
./philo 5 800 200 100
For more detailed information, please refer to the project documentation and the source code comments.