Skip to content

Philosophers is a simulation project written in C to discover threads and mutexes.

Notifications You must be signed in to change notification settings

LoisDuplain/philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

👴🏻 philosophers 🍴

platform: osx 10.14.x language: c 42 login: lduplain

Philosophers is a simulation project written in C to discover threads and mutexes.

One or more philosophers are sitting at a round table either eating, either thinking, either sleeping.
While they are eating, they do not think or sleep.
While thinking they don’t eat or sleep and while sleeping, they do not eat or think.

The philosophers sit at a circular table with a large bowl of spaghetti in the center.
There are some forks on the table.
Serving and eating spaghetti with a single fork is very inconvenient, so the philosophers will eat with two forks, one for each hand.

Each time a philosopher finishes eating, they will drop their forks and start sleeping.
Once they have finished sleeping, they will start thinking.
The simulation stops when a philosopher dies.

Created by Loïs Duplain. (42login: lduplain, 42mail: lduplain@student.42lyon.fr)

🏗️ Compile

To basically compile program:

make

To recompile entire program:

make re

To clean all *.o in project:

make clean

To clean all *.o and compiled program in project:

make fclean

▶️ Run

To run and see usage:

./philo

Result:

Usage:
	./philo <number_of_philosophers> <time_to_die> <time_to_eat> <time_to_sleep> [number_of_times_each_philosopher_must_eat]
		Example = ./philo 5 800 200 200
	
	Optional number_of_times_each_philosopher_must_eat:
		Example = ./philo 5 800 200 200 5

Default simulation:

./philo 5 800 200 200

The philosopher should not eat and die:

./philo 1 800 200 200

No one should die and simulation should stop when all philosophers has eaten 7 times:

./philo 5 800 200 200 7

To count how many times a philsopher has eaten:

./philo 5 800 200 200 7 | grep "? is eating" | wc -l	(replace "?" by a philosopher ID)

To test simulation optimization:

./philo 4 410 200 200					(No one should die)

My code is well optimized so this should work:

./philo 4 401 200 200					(No one should die)

🖥️ 42

Subject

Mark: 42-project-mark

⚖️ Copyright

Loïs Duplain (lduplain) © 2021

About

Philosophers is a simulation project written in C to discover threads and mutexes.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published