Philosopher is a project under the curriculum of 42 School. This project is designed to help students understand the basics of threading a process. It aims to learn the basics of threading a process and how to work with the same memory space.
Students will learn about the dining philosophers problem and how to avoid common issues such as deadlock. They will also learn how to use semaphore and mutex in a multi-threading environment.
- Understand the basics of threading a process
- Understand how to use mutex and semaphore
- Understand how to avoid deadlock in a multi-threading environment
In order to run the Philosopher project, you will need to compile it first. This can be done by using the make
command in the root directory of the project. This command will compile all the necessary files and create an executable file called philo
.
To run the program, you can use the following command: ./philo
. This command runs the executable file.
The philo
program requires you to pass several arguments:
- Number of philosophers: This is the total number of philosophers sitting at the table.
- Time to die: If a philosopher doesn’t start eating ’time to die’ milliseconds after starting his last meal or the beginning of the simulation, it dies.
- Time to eat: The time it takes for a philosopher to eat. During that time he will need to keep the two forks.
- Time to sleep: Time the philosopher will spend sleeping.
- Number of times each philosopher must eat: argument is optional, if all philosophers eat at least ’number of times each philosopher must eat’ the simulation will stop. If not specified, the simulation will stop only at the death of a philosopher.