Questions tagged [dining-philosopher]

The dining philosophers problem is an example problem often used in concurrent algorithm design to illustrate synchronization issues and techniques for resolving them.

5 philosophers sit around a circular table. Each philosopher spends his life alternatively thinking and eating. In the centre of the table is a large plate of noodles. A philosopher needs two chopsticks to eat a helping of noodles. Unfortunately, as philosophy is not as well paid as computing, the philosophers can only afford five chopsticks. One chopstick is placed between each pair of philosophers and they agree that each will only use the chopstick to his immediate right and left.

The problem to solved is how should the philosophers behave to avoid starvation or deadlocks.

For a full description and discussion, see the wikipedia article.

96 questions
0
votes
0 answers

Using Named Semaphore to synchronise between process

I am trying to implement a modified form of classic dining philosophers problem. Suppose there are 5 philosophers sitting on the table. There are 3 forks and 3 spoons placed on the table. A philosopher can pick any spoon or fork on the table. A…
FrackeR011
  • 61
  • 10
0
votes
0 answers

How to add sequence for my tasks execution?

Sorry for my bad english and thank you very much for your help. I have a class that starts my tasks : Report report = new Report(); //Fork to left of Plato and right of Galileo. Fork fork1 = new Fork(1, report); …
0
votes
1 answer

How can i write an adaptive method to use my library in the right way?

I have a library and theres one problem with the logic in my program. If you can help me - i will say you : "Thank you" . really big thanks. Code : public class Report { /// /// An empty constructor, just instantiates the…
0
votes
1 answer

dining philosopher java alternative solution

I found on a book this alternative solution for "Dining philosopher problem", in Java: public class Philosopher extends Thread { private final int maxPause = 100; private int bites = 10; private Chopstick lower; private Chopstick higher; private…
lucacatr
  • 101
  • 3
  • 12
0
votes
0 answers

Dining Philosophers implementing pipes in C

Have to design the Dining Philosophers program while using pipes for a class. Having some trouble in the piping message passing. Here's my code so far: #include #include #include #include #include…
0
votes
1 answer

Thread.join() is not working at expect in Dining Philosophers implementation

I have implemented the Dining Philosopher problem using Monitor (Synchronized) in Java. The goal of this program is: Every philosopher should follow the workflow of think, get chopsticks, eat, put chopsticks (no race conditions). No Deadlock I…
0
votes
2 answers

notifyAll() not awakening processes

I'm programming a little Java program where I need to create threads (philosophers in my code), and these philosophers need to change of state between thinking, hungry and eating. I'm not that far into the project and I have the next…
Erick Siordia
  • 171
  • 1
  • 10
0
votes
1 answer

Dining Philosophers implementation using monitors

In Dining Philosophers implementation with a monitor, why does the putdown() operation call the test() operation twice? procedure take_chopsticks(i) { DOWN(me); pflag[i] := HUNGRY; test[i]; UP(me); …
JimmyFails
  • 113
  • 6
0
votes
1 answer

Showing deadlock, using Pthreads, on Dining Philosophers

We have an assignment to show deadlock with the Dining Philosophers problem. We've coded it all and the code compiles but when running the code, one of the philosophers eventually eats. So doesn't that mean deadlock doesn't actually occur? #include…
0
votes
0 answers

Dining Philosopher Testing Deadlock

I am implementing the dining philosopher problem in c using semaphores. My code works although i am confused as to why no deadlock is occurring at all. CODE: #include #include #include #include sem_t…
xSooDx
  • 493
  • 1
  • 5
  • 19
0
votes
1 answer

C++/cli error C4368: cannot define 'list' as a member of managed 'queue': mixed types are not supported

I'm totally new to c++ Gui.. i'm trying to make a simple windows form to draw on my dining philosophers semaphore solution my semaphore header file ref class sema4 { private: int sem_value; queue Waiting_List; public: sema4(); void…
0
votes
0 answers

Monitor time for a given structure in C

I am working on an equivalent to the Dining Philosopher problem in C. Our subject has a few new rules, adding a Resting state and the following rule: "The states 'think' and 'eat' have a maximum duration that you'll have to determine." The following…
user5448913
0
votes
1 answer

Concurrency in erlang and dining philosphers

Im tackling the dining philosophers algorithm. I need to spawn 5 philosophers which I have done so using this code main() -> philos1 = spawn (?MODULE, philosopher, []), philos2 = spawn (?MODULE, philosopher, []), philos3 = spawn…
iain man
  • 7
  • 2
0
votes
2 answers

Dining philosophers - I spoke to all, just one listens

I'm implementing dining philosophers problem and I faced a problem myself, I do not know what's the cause, hence I am here. It is after dinner when I'm telling them to leave, I want to force them to create reports cause that's the next stage of…
Suspended
  • 1,184
  • 2
  • 12
  • 28
0
votes
1 answer

Chandy/Misra dining philosophers solution

So based on the Chandy/Misra section in this Wikipedia article we've got 5 philosophers numbered P1-P5. Based on this quote: For every pair of philosophers contending for a resource, create a fork and give it to the philosopher with the lower ID (n…