This project is a simulation of the dining philosophers problem. The program creates a certain number of philosophers and forks. Each philosopher can be in one of three states: eating
, sleeping
, thinking
. The philosopher can only eat if he has two forks. The program uses threads and mutexes to synchronize the philosophers' actions.
The dining philosophers problem is a classic synchronization problem. The problem consists of a table with five philosophers sitting around it. Each philosopher has a plate of spaghetti. A fork is placed between each pair of adjacent philosophers. A philosopher needs two forks to eat. The problem is how to design a discipline of behavior (a concurrent algorithm) such that each philosopher will not starve, i.e., each can eat forever often.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
What things you need to install the software and how to install them.
gcc >= 7.5.0
make >= 4.1
sudo apt-get install make
sudo apt-get install gcc
A step by step series of examples that tell you how to get a development env running.
Clone the repository.
git clone https://github.com/LudwigAndreas/philosophers42
cd philosophers42
Build the project.
make
or build with bonus.
make bonus
Run the project.
./philo number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]
Explain how to run the automated tests for this system.
make test
After running the program, you will see how the philosophers are eating, sleeping, and thinking.
This project was developed by:
LudwigAndreas |
---|
This project is licensed under the School 21 License - see the LICENSE file for details.