GithubHelp home page GithubHelp logo

dining-philosophers-multithreading's Introduction

dining-philosophers-multithreading

https://en.wikipedia.org/wiki/Dining_philosophers_problem

Problem statement:

Five philosophers dine together at the same table. Each philosopher has their own plate at the table. There is a chopstick between each plate. The dish served has to be eaten with two chopsticks. Each philosopher can only alternately think and eat. Moreover, a philosopher can only eat their dish when they have both a left and right chopstick. Thus two chopstick will only be available when their two nearest neighbors are thinking, not eating. After an individual philosopher finishes eating, they will put down both chopstick. The problem is how to design a regimen (a concurrent algorithm) such that no philosopher will starve while beeing stuck with only one chopstick; i.e., each can forever continue to alternate between eating and thinking, assuming that no philosopher can know when others may want to eat or think

Solution:

working with priorized chopsticks: each philosopher is set-up to pick up the lower (left) chopstick first, except of the last philosopher who does in reverse, so that philosophers won't get stuck.

The threading library is used for multithreading and the lock/ release mechanism guards against simultaneous access to a chopstick

dining-philosophers-multithreading's People

Contributors

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