Skip to content

Latest commit

 

History

History
80 lines (49 loc) · 1.97 KB

README.md

File metadata and controls

80 lines (49 loc) · 1.97 KB

philosophers

Info

42 Cursus - philosophers: this project is a training to multi-threads/multi-process programming.

  • Status: finished
  • Result: 125%
  • Observations: (null)

The philosophers problem

The classic dining philosopher problem.

This problem states that N philosophers seated around a circular table with one fork between each pair of philosophers. A philosopher may eat if he can pick up the two forks adjacent to him. One fork may be picked up by any one of its adjacent followers but not both.

Each time a philosopher finish eating, they will drop drop their forks and start sleeping. Once they have finished sleeping, the will start thinking and waiting to eat.

Simulation stops when a philosopher dies.

Every philosopher needs to eat and they should never starve.

Philosophers do not speak with each other.

Philosophers do not know when another philospher is about to die.

And of course, philosophers should avoid dying.

Solutions

philo: philosophers with threads and mutex.

  • One fork between each pair of philosophers.

philo_bonus: philosophers with processes and semaphore.

  • All the forks are in the middle of the table.

How to use

Clone the repo

git clone https://github.com/izenynn/libft.git

Go to philo or philo_bonus folder and run make

cd ./philo && make
cd ./philo_bonus && make
  • Makefile rules: all, clean, fclean, re).

Usage

./philo [N PHILOS] [DIE TIME] [EAT TIME] [SLEEP TIME] (OPT)[PHILO EAT N TIMES]
  • last argument is optional.

  • philo_bonus takes the same arguments as philo.

Example

./philo 4 800 200 200
./philo_bonus 10 410 200 200 7

forthebadge forthebadge