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.
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.
Browser other questions tagged python algorithm
You are not signed in. Login or sign up in order to post.
If you show us what you have already implemented, we can help you.
– ptkato
If you can’t use thread, you can use what then? Processes?
– mgibsonbr
Exactly. I need to communicate between processes and deal with deadlock and starvation cases.
– Francielle oliveira
I suggest you take a look at the package
multiprocessing
, it has an API similar to the modulethreading
(simplifying your adaptation). By way of example, you can create aLock
to represent the shared resource, usingl.acquire()
andl.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...– mgibsonbr
If this is a "broad" problem I don’t know what would be specific. A question doesn’t need to be a treaty.
– Motta