The Philosophers project is a C language implementation inspired by the classic Dining Philosophers problem—an example often used in computer science for illustrating synchronization, concurrency, and deadlock avoidance.
- C (84.9%): Core logic, thread management, synchronization.
- Makefile (15.1%): Build instructions and project automation.
The Dining Philosophers problem models a scenario where several philosophers sit at a table with forks between them. Each philosopher alternates between thinking and eating. To eat, a philosopher must acquire both adjacent forks. The challenge is to design a system that prevents deadlocks and ensures that every philosopher can eat and think without starvation.
- Thread-based simulation of philosophers’ actions.
- Solutions for preventing deadlocks and starvation.
- Customizable simulation parameters (number of philosophers, timings).
- Clean, modular C codebase.
- GCC or compatible C compiler
- Make
make./philosophers <number_of_philosophers> <time_to_die> <time_to_eat> <time_to_sleep> [number_of_times_each_philosopher_must_eat]number_of_philosophers: Number of philosophers at the tabletime_to_die: Time (ms) before a philosopher dies if not eatingtime_to_eat: Eating duration (ms)time_to_sleep: Sleeping duration (ms)[number_of_times_each_philosopher_must_eat]: (Optional) simulation stops when all have eaten this many times
./philosophers 5 800 200 200src/— C source files for the simulation logicinclude/— Header filesMakefile— Build automation
Feel free to fork, open issues, or submit PRs for improvements and bug fixes.
This project follows the license provided in the repository.