Skip to content

A version of the dining philosophers with a few extra restrains.

Notifications You must be signed in to change notification settings

cyanidev/Philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Dining Philosophers problem

Philosophers is a 42 school project that illustrates synchronization issues and techniques for resolving them in concurrent algorithm design. Similar to the one that was formulated by Edsger Dijkstra in 1965 as a student exam exercise.

alt text

General instructions

  • Global variables are forbidden!
  • Your program(s) must accept the following arguments:
number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]

number_of_philosophers (int between 1 and 200): is the number of philosophers, but also the number of forks.
time_to_die (in milliseconds): if a philosopher doesn't start eating within time_to_die milliseconds from the start of their last meal or from the beginning of the simulation, they will die.
time_to_eat (in milliseconds): is the time a philosopher has to eat. During this time, they will have the forks occupied.
time_to_sleep (in milliseconds): is the time a philosopher has to sleep.
number_of_times_each_philosopher_must_eat (optional argument): if all philosophers eat at least number_of_times_each_philosopher_must_eat times, the simulation will stop. If not specified, the simulation will stop with the death of a philosopher.

  • Each philosopher will be assigned a number from 1 to number_of_philosophers.
  • Philosopher number 1 will sit next to philosopher number number_of_philosophers. Any other philosopher number N will sit between philosopher number N - 1 and philosopher number N + 1.

The logs of the program:

Any change in the state of a philosopher follow this format:

◦ timestamp_in_ms X has taken a fork
◦ timestamp_in_ms X is eating
◦ timestamp_in_ms X is sleeping
◦ timestamp_in_ms X is thinking
◦ timestamp_in_ms X died

To run the program:

Compile the program with:
make

Run the program with the following arguments:

./philo <number_of_philosophers> <time_to_die> <time_to_eat> <time_to_sleep> [number_of_times_each_philo_must_eat]

example(no philo dies):

./philo 4 410 200 200

example(one philo dies):

./philo 4 310 200 100

example(with opcional parameter):

./philo 5 800 200 200 7

If the inputs are correct, the software will document each philosopher's actions until one passes away or until they've all reached the specified number_of_times_each_philo_must_eat, if that parameter is given.

About

A version of the dining philosophers with a few extra restrains.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published