philosophers is a project that involves solving the classic Dining Philosophers Problem using synchronization techniques in C. The goal of this project is to understand and manage concurrency and synchronization between multiple processes or threads.
The Dining Philosophers Problem is a classic synchronization issue where five philosophers sit at a round table with a fork placed between each pair of adjacent philosophers. Each philosopher must alternately think and eat. However, to eat, a philosopher needs both forks on either side. The challenge is to design an algorithm to avoid deadlock and ensure that every philosopher gets a chance to eat.
- Implement a solution to the Dining Philosophers Problem using mutexes and condition variables.
- Ensure no deadlock occurs.
- Ensure that no philosopher starves and every philosopher gets a chance to eat.
- Handle edge cases such as no philosophers, or an even number of philosophers.
- A Unix-based system (Linux or macOS)
gcccompiler andmake- Basic understanding of concurrency and synchronization
-
Clone the repository:
git clone https://github.com/arnoop88/philosophers.git cd philosophers -
Compile the project:
make
To run the program, you need to specify the number of philosophers, the time to die, the time to eat, and the time to sleep in ms. You can also specify the number of times each philosopher has to eat in order to finish the program. For example:
./philosophers 5 800 200 200 5