Solving threads' concurrent and deadlock problem using mutexes
The philosopher simulation is about “dining philosopher problem,” a famous problem in operating systems. The eating philosopher problem is a representative “simultaneity control” problem, in which two people must prevent two people from holding the same chopsticks (or fork) at the same time (mutual exclusion), while avoiding deadlocks where each person holds one chopstick and asks for the other person’s chopsticks.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Git clone the repository
$make
$./philo [number_of_philosophers] [time_to_die] [time_to_eat] [time_to_sleep] [number_of_times_each_philosopher_must_eat]
- After the simulation started, if the philosopher doesnt eat wihtin
time_to_die
ms after the last meal
- while eating, one philosopher needs two forks(its left side and right side)
- Simulation stops when all the philosophers eat Nth amount of time
- If this is not given, simulation should only stop when one of the philosopher dies
0 < number_of_philosophers < 200 || time_to_die > 60 || time_to_eat > 60 || time_to_sleep > 60
- If the number of philsopher is odd, it should be more than 1 philosopher, time to die should be triple the amount of time to eat, time to sleep.
$./philo 3 510 200 200
- If the number of philsopher is even, it should be more than 1 philosopher, time to die should be triple the amount of time to eat, time to sleep.
$./philo 4 410 200 200