Giter VIP home page Giter VIP logo

42-philosophers's Introduction

⚙️ philosophers (a 42 project) ⚙️

📑 Introduction

School 42's philosophers project about introduction of the basics of process threading, how to work on the same memory space. How to deals with dataraces by using mutexes.
The goal of this project is to write a program in C that creates a given number of threads in the same process, and each threads will have to follow a routine during which it will have to perform some tasks, such as locking / unlocking mutexes and wait certain amounts of time.
The threads are called philo, each philos must eat from time to time to avoid starvation. To eat, they must have a fork in each hand. The forks are represented by mutexes, there are as many forks as philos. To be able to eat, the philos have to share the forks, alternating meals between them.

Routine to be executed by philos:

  • Take a fork: The philo/thread locks a mutex/fork.
  • Eat: Once the philo/thread locked two mutexes/forks, it can eat, and wait for a set amount of time.
  • Sleep: Once the philo/thread has finish eating, it falls asleep and waits for a set amount of time.
  • Think: Once the philo/thread wakes up, it thinks, waiting for forks/mutexes to be available.

If a philo doesn't eat for too long, it dies. The aim of this project is to program such philos, and make sure they don't die.

Subject : en.philosophers_subject.pdf

My grade

nsalles's 42 Philosophers Score

Usage

Download philosophers and enter the repo:

git clone https://github.com/Floperatok/42-philosophers.git && cd 42-philosophers

There are two folder philo and philo_bonus, the philo folder is the classic program with thread as philos. The philo_bonus is the bonus folder where philos are not longer represented by threads but by process, and forks are no longer represented by mutexes but by semaphores. Go inside of the folder of your choice, then compile :

make && make clean

You can now execute the program with the necessary arguments:

./philo 5 800 200 200

Note: if you choose the bonus folder, the program name is philo_bonus
The first argument is the number of philos.
The second arguement is the time in millisecond it takes a philo to starve.
The third arguement is the time in millisecond it takes a philo to eat.
The fourth arguement is the time in millisecond it takes a philo to sleep.
It is possible to enter a fifth argument which is the number of times the philo must eat before the program stops, the program does not stop by default.

42-philosophers's People

Contributors

floperatok 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.