Philosophers' Dinner in Python

Asked

Viewed 816 times

2

I wonder if anyone has implemented the python Philosophers' Dinner algorithm.

I need to do it, but only find examples with implementation using thread and need to do without using thread.

  • 3

    If you show us what you have already implemented, we can help you.

  • 2

    If you can’t use thread, you can use what then? Processes?

  • Exactly. I need to communicate between processes and deal with deadlock and starvation cases.

  • 1

    I suggest you take a look at the package multiprocessing, it has an API similar to the module threading (simplifying your adaptation). By way of example, you can create a Lock to represent the shared resource, using l.acquire() and l.release() to catch it and release it respectively. Here is an example. And what is the need for communication for this algorithm? To my knowledge, philosophers do not interact directly with each other...

  • 1

    If this is a "broad" problem I don’t know what would be specific. A question doesn’t need to be a treaty.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.