Giter Club home page Giter Club logo

42cursus-philosophers's Introduction

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 [email protected]: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.

42cursus-philosophers's People

Contributors

ygor-sena avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.