Giter VIP home page Giter VIP logo

philosophers's Introduction

philosophers

I never thought philosophy would be so deadly

Description of the subject

Philosophers is a project about solving the dining philosophers problem by writing a simulation of philosophers sitting around a table. The philosophers alternatively eat, think, or sleep. Once a philosophers is done eating he will sleep, afterwards think and then eat again. There is a fork for every philosopher and 2 forks are needed for a philosopher to eat. Once a philosopher starts eating his time to die will be reset and the other philosophers can't access the forks anymore while he eats. If a philosopher dies the simulation will stop.

This project is about writing effective code, learning about threads, mutexes and all the problems that may come along with it, like data races.

For more details: subject.pdf

Installation and execution

  1. git clone or fork the repository
  2. run make to create the executeable
  3. run it with ./philo and the needed arguments (amount of philos, time to die, time to eat, time to sleep, *number of meals)

*number of meals is not necessary for the simulation to work

Sources and tips for 42 students

  • I really recommend watching the threads videos by CodeVault to get started with threads
  • Even though I didn't use one, I recommend using a *"reaper thread" because it makes your simulation way faster
  • Mutex lock everytime you access a shared variable to avoid data races, bools don't need to be locked necessarily because they only have 2 values

*a reaper thread is a thread running along with the philosophers checking if one of them died and if so exiting the program

philosophers's People

Contributors

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