The "Philosophers" project is part of the 42 Network's Common Core curriculum. It revolves around the famous "Dining Philosophers" problem, which is a classic synchronization issue in computer science used to illustrate the challenges of resource sharing and concurrency.
The project aims to train students in multi-threading and multi-process programming using mutexes and semaphores. It involves implementing simulations of the Dining Philosophers problem with different synchronization techniques.
Dining Philosophers Problem:
- Philosophers sit at a circular table with a bowl of spaghetti and a fork between each pair.
- Each philosopher must alternate between eating, thinking, and sleeping.
- To eat, a philosopher needs two forks, which introduces a challenge to avoid deadlock and ensure no philosopher starves.
Project Variants:
- Mandatory part : Uses multi-threading with mutexes.
- Bonus part : Uses multi-processing with semaphores.
- The simulation must ensure that no philosopher starves.
- Philosophers do not communicate with each other.
- The simulation stops when a philosopher dies of starvation.
- The project must be coded in C, adhering to the 42 Norm, which includes strict coding standards and no memory leaks or crashes.
git clone https://github.com/lassachraf/42_Philosophers.git
cd 42_Philosophers
- For mandatory :
make
./philo nb_philo time_to_die time_to_eat time_to_sleep max_meals
- For bonus :
make bonus
./philo_bonus nb_philo time_to_die time_to_eat time_to_sleep max_meals
- nb_philo : Number of philosophers.
- time_to_die : Time to die in milliseconds.
- time_to_eat : Time to eat in milliseconds.
- time_to_sleep : Time to sleep in milliseconds.
- max_meals : Number of times each philosopher must eat (Optional parameter).
- Managing concurrency and synchronization in software development.
- Using mutexes and semaphores to handle shared resources.
- Optimizing C code for performance, which is critical for real-time systems.