GithubHelp home page GithubHelp logo

okbrandon / philosophers Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 69 KB

๐Ÿฝ๏ธ dining philosophers problem in C.

Makefile 14.47% C 85.53%
42cursus 42projects 42school philosophers-dinner-problem philosophers42

philosophers's Introduction

๐Ÿฝ๏ธ philosophers

Philosophers is a 42 school project that consists in creating a program that reproduce the dining philosophers problem.

Top used language Norminette run GitHub last commit

๐Ÿ“š Table of Contents

๐Ÿ‘จโ€๐Ÿซ Demonstration

Screen.Recording.2023-04-27.at.5.49.19.PM.mov

Running simulation with 5 philosophers. ./philo 5 800 200 200

๐Ÿ“ฆ Installation

Clone the repository from GitHub:

git clone https://github.com/okbrandon/philosophers.git

Compile the philo executable:

cd philo/ && make

Compile the philo_bonus executable:

cd philo_bonus/ && make

๐Ÿ“ Usage

Run the mandatory program:

./philo <num_of_philo> <time_to_die> <time_to_eat> <time_to_sleep> [<must_eat>]

First parameter is how much philosophers you want, the second one is after how many millis they should die after their last meal, the third one is the time they take to eat in millis, same for the forth parameter. The last one is optional and represent how many times each philosopher should eat at least.

Run the bonus program:

./philo_bonus <num_of_philo> <time_to_die> <time_to_eat> <time_to_sleep> [<must_eat>]

Same as above.

๐Ÿ“ Example

Valid simulation:

$> ./philo 5 800 200 200
0           1 has taken a fork
0           3 has taken a fork
0           3 has taken a fork
0           3 is eating
0           1 has taken a fork
0           1 is eating
0           5 has taken a fork
200         4 has taken a fork
200         3 is sleeping
200         5 has taken a fork
200         5 is eating
200         1 is sleeping
200         2 has taken a fork
200         2 has taken a fork
200         2 is eating
[...]

Invalid simulation:

$> ./philo 5 400 200 200
0           1 has taken a fork
0           1 has taken a fork
0           1 is eating
0           3 has taken a fork
0           3 has taken a fork
0           5 has taken a fork
0           3 is eating
200         3 is sleeping
200         5 has taken a fork
200         5 is eating
200         1 is sleeping
200         4 has taken a fork
200         2 has taken a fork
200         2 has taken a fork
200         2 is eating
400         3 is thinking
400         3 has taken a fork
400         2 is sleeping
400         5 is sleeping
400         1 is thinking
400         1 has taken a fork
400         4 has taken a fork
400         4 is eating
400         1 died

The bonus program has the same output as the mandatory one. The only difference is that the mandatory uses mutexes and the bonus one semaphores.

โฌ† Back to Top

๐ŸŒ Meta

bsoubaig โ€“ [email protected]

philosophers's People

Contributors

brandonlooksdumb avatar okbrandon avatar

Stargazers

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