Skip to content

Chandy/Misra solution of the dining philosophers problem using python

License

Notifications You must be signed in to change notification settings

lievi/dining_philosophers

Repository files navigation

Dining Philosophers solution example

codecov

Chandy/Misra solution of the dining philosophers problem using python threads, Lock and Condition alt dining philosophers problem

The Dining philosophers is a synchronization problem which is used to evaluate situations where there is a need of allocating multiple resources to multiple processes. The problem is:

Consider there are five philosophers sitting around a circular dining table. The dining table has five forks and a bowl of food in the middle. At any instant, a philosopher is either eating or thinking. When a philosopher wants to eat, he uses two forks - one from their left and one from their right. When a philosopher wants to think, he keeps down both forks at their original place. Eating is not limited by the remaining amounts of food;

Solution

  • The philosopher have a tuple of the neighbors forks
  • The fork have a current owner
  • A philosopher can only eat if he is owner of both neighbors forks
  • When the philosopher wants to eat, he request the forks that he is not owner and waits until the others philosophers finish using it.
  • When a philosopher finish eat, he change the state of the fork to dirty, and send a "signal" that he is finished eat.

For more information about the Chandy/Misra solution, please visit the references links.

References

How to use?

  • Install de dependecies on pyproject.toml (generated using poetry)
  • run the main.py file

License

A short snippet describing the license (MIT, Apache etc)

MIT © Lievi Silva

About

Chandy/Misra solution of the dining philosophers problem using python

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages