Skip to content

The ninth project of 42's curriculum asks students to solve the famous Dijkstra's synchronization problem. This is a introduction to threads, mutexes and semaphores.

License

Notifications You must be signed in to change notification settings

ygor-sena/42cursus-philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OS Language Grade Status

📣 Introduction

The ninth project of 42's curriculum asks students to solve the famous Dijkstra's synchronization problem called The Dining Philosophers Problem. This is a introduction to multithreads, multiprocesses, mutexes and semaphores.

⚒️ How to compile and run the project

1) Copy this repository to your local workstation

git clone git@github.com:ygor-sena/42cursus-philosophers.git

2) Choose the mandatory or bonus folder to compile the project

To compile the mandatory project, execute the following command in your terminal:

cd philo/ && make

Otherwise, if you want to compile the bonus version, execute:

cd philo_bonus/ && make

3) Run the program

Both the mandatory and bonus program take at least 5 arguments. The first parameter is the program's binary file and the last one is optional. Each of them stands for:

#2 #3 #4 #5 #6 (optional)
5 800 200 200 5
number_of_philosophers time_to_die time_to_eat time_to_sleep number_of_times_each_must_eat

So, to start a dinning simulation where there are 5 philosophers that must eat 7 times each and the time to die, to eat and to sleep is 800, 200 and 200 respectively, we should execute the following command:

./philo 5 800 200 200 7

4) How to check for memory leaks and data race conditions

Run the program with the valgrind's flags below to check for memory leaks:

valgrind -q --leak-check=full --show-leak-kinds=all --track-origins=yes

Also, run the program with valgrind's tools DRD (Data Race Detector) and Helgrind separately to search for data race conditions and typical syncronization problems such as deadlock:

valgrind --tool=drd 
valgrind --tool=helgrind 

⚠️ Known issues

There are cases where a philosopher can die because the scheduler priorized some threads/processes instead of giving all of them the same priority. To avoid this, it is necessary to implement a function that always will make the hungriest philosopher dinner first. It is possible to implement this in the mandatory project according the rules of the subject. For the bonus project, we would need shared memory to share information between the child processes, but its use is not allowed by the subject.

📖 References

🫂 Acknowledgements

I want to thank Marcelo Magalhães, also a student at 42SP for his support throughout the project when I needed. Please, check out his interesting projects at GitHub here.

About

The ninth project of 42's curriculum asks students to solve the famous Dijkstra's synchronization problem. This is a introduction to threads, mutexes and semaphores.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published