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
13
votes
2 answers

possibility of starvation of Dining Philosophers

I need to check my algorithm of solving the dining philosopher problem if it guarantees that all of the following are satisfied or not: No possibility of deadlock. No possibility of starvation. I am using the semaphore on the chopsticks to solve…
Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
7
votes
3 answers

Non-blocking solution to the dining philosophers

I have been asked to write a simple solution to the dining philosophers problem in python. That itself seems quite straight forward but am some what confused since I am asked to write a non-blocking solution. I am unsure what is meant by this in…
Seb
  • 117
  • 1
  • 6
5
votes
0 answers

programming dining philosophers program with MPI C

I have a problem with my MPI C program. This is the code: void wantEat(int p, int rank, char *state, char* stateLeft, char* stateRight){ char *s; MPI_Status status ; /* if left or right neighbor is eating */ if(compare(stateLeft,…
test87
  • 61
  • 3
5
votes
2 answers

Real world example of Dining philosophers?

Producer/Consumer and Reader/Writer are easy to think of, but how about Dining philosophers? Under what kind of situation that N processes and N resources will lay on a ring topology and interleaving to each other? I could think of N processes…
Ray Wu
  • 993
  • 16
  • 34
3
votes
2 answers

Starvation in the dining philosopher problem

I've been looking at a solution for the dining philosopher problem on wikipedia. The resource hierarchy solution I understand how it works and how breaking the circular structure prevents deadlocks but how does the solution prevent starvation?…
3
votes
1 answer

mixture of left-handed and right-handed philosophers, a tricky questions?

Lemma 1: we know at any table with a mixture of left-handed and right-handed philosophers, deadlock cannot occur. I very familiar with it proofs. I ran into a following question on Interview recently. There are 5 philosophers sitting at a round…
3
votes
1 answer

Dining Philosophers in C using fork()

I wrote a C program for the Dining Philosophers Problem using pthread some time ago and am now trying to change it to use fork() instead. This is an exercive for a lecture I already passed. But a friend asked me for help and I can't seem to get it…
sfey
  • 97
  • 2
  • 8
3
votes
1 answer

Java dining philosophers monitors

I have a problem in my Java code that should simulate dining pholosophers problem, which is described here: http://en.wikipedia.org/wiki/Dining_philosophers_problem I want to output the current state of all philosophers every time one of them eats…
3
votes
1 answer

Using java code in pnml to represent Colored Petri Net

When we write a Colored Petri Net (CP-Net), can we use java code in the declaration section like the following example in PNML, or we have to consider a standard in this part also? the following example is an XML representation, but can we use the…
user1149501
2
votes
2 answers

Dining Philosophers problem - A Clarification needed

Recently I read this Wikipedia article regarding the Dining Philosophers problem but I am not clear with Chandy / Misra solution. According to the article, "When a philosopher with a fork receives a request message, he keeps the fork if it is clean,…
Chathuranga Chandrasekara
  • 20,548
  • 30
  • 97
  • 138
2
votes
2 answers

Dining philosophers in java leads to deadlock

I have implement dining philosophers problem in java but something goes wrong and it leads to deadlock... Can someone spot why this leads to deadlock? The philosophers should always be N-1 in the dining room so everyone can eat and prevent…
stelios
  • 1,027
  • 3
  • 14
  • 19
2
votes
1 answer

How to solve the dining philosophers problem with only mutexes?

I wrote this program to solve the dining philosophers problem using Dijkstra's algorithm, notice that I'm using an array of booleans (data->locked) instead of an array of binary semaphores. I'm not sure if this solution is valid (hence the SO…
soufiane yakoubi
  • 861
  • 11
  • 31
2
votes
1 answer

dining philosophers with deadlock livelock and starvation

this is a solution for the dining philosophers problem from geeksforgeeks using semaphores: #include #include #include #include #define N 5 #define THINKING 2 #define HUNGRY 1 #define EATING 0…
2
votes
4 answers

Another way to solve the Dining Philosopher (need a point in the right direction)

for a programming assignment I have been asked to implement a solution to the Dining Philosopher problem. I must do so in two ways: Use the wait() and notifyAll() mechanism Using an existing concurrent data structure provided in the Java API I…
Logan Serman
  • 29,447
  • 27
  • 102
  • 141
2
votes
1 answer

Dining philosophers problem - only 2 thread worked

I am trying to solve the dining philosophers problem. In my case, every philosopher should eat 1,000,000 times. The problem is that it seems like only "1" and is "3" finished eating. I am using threads with critical section lock, here is my…
וי חנ
  • 79
  • 6
1
2 3 4 5 6 7