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
1 answer

Auction implementation similar to Dining Philosophers

I am trying to implement an auction concept in netlogo - it is similar to the dining philosophers problem program. My program deals with computers and processors that correspond to philosophers and forks in the dining philosopher program. In the…
Tanya Kapoor
  • 3
  • 1
  • 5
0
votes
1 answer

Passing information to multiple threads in the dining philosopher's algorithm

I am trying to create multiple threads and pass a different value to each thread for the dining philosopher's problem. But I am getting this error: warning: cast to pointer from integer of different size Here is my code: pthread_mutex_t…
user1435077
  • 49
  • 1
  • 6
0
votes
1 answer

Netbeans, red text but no error

I'm trying to implement a solution to the Dinning Philosophers. Not sure if I'm doing it right. My program isn't crashing but I am getting red text in the output, but there's no error code. Example of the error: at…
The Muffin Boy
  • 314
  • 4
  • 14
0
votes
1 answer

How to determine when threads are in a deadlock from Main C#

I have read other posts about tools for deadlock detection and avoiding deadlock; but my question is specifically about how to find when threads are in deadlock from Main so that I can make the Main thread sleep until the threads are deadlocked and…
inspiringmyself
  • 590
  • 1
  • 11
  • 29
0
votes
3 answers

Dining philosophers and mutex initialization

I am trying to solve dining philosophers problem.So I pretty much made entire code but the problem is that I can't initialize monitors(i've made pseudocode which I re-written in c++) so really I can't test the program. Can anyone help me and say…
T0plomj3r
  • 685
  • 1
  • 9
  • 23
0
votes
2 answers

Java Philosopher diner

I have been working on the philosopher dinning task and I have a problem, my code revolves around 3 classes, Forks, philosophers and dinerTable (yes I named the last two with small letters by mistake). The code starts properly, philosopher 0 and 2…
Ted
  • 629
  • 2
  • 8
  • 19
0
votes
3 answers

Dining Philosopher - Last thread not terminating properly

I wrote this Dining Philosopher code but the last thread does not produce the desired "xxx has finished his dinner" line? What did I do wrong? It seems the last thread terminates prematurely. I would appreciate any help on this. import…
user1872371
  • 321
  • 2
  • 12
0
votes
0 answers

Are the forks in fixed places in the philosopher dinner?

The philosophers dinner is a classic concurrency problem. See description here. In the Conductors solution are the forks put back in specific places or just put into a general heap. So will the left fork for any philosopher be the same left fork?…
Breako Breako
  • 6,353
  • 14
  • 40
  • 59
0
votes
1 answer

Compilation error: "The last statement in a 'do' construct must be an expression"

The following is my dining philosophers code and yields a compilation error saying "The last statement in a 'do' construct must be an expression: mVar2 <- newEmptyMVar mVar3" Can Somebody help me fix this error and get this program working? thank…
prince89
  • 3
  • 3
-1
votes
1 answer

How should I solve starving in Dinning Philosophers problem using conditional variables?

I have written simple program simulating Dinning Philosophers using condition_variables, problem is that some philosophers never gets opportunity to eat. I have tried to putting breakpoints inside _condVar.Wait lambda function to make sure, that…
Macko
  • 139
  • 7
-1
votes
1 answer

Operation with "%" give an unexpected result

Im working in the Dining Philosophers Problem. For distribute the forks im using this loop that i found: int philosophersNumber=5; for (int i = 0; i < philosophersNumber; i++) { philosophers[i] = new Philosopher( i, …
TheRedosan
  • 79
  • 2
  • 12
-1
votes
1 answer

Dining philosophers using binary semaphores

Can this pseudocode solve the dining philosopher problem with maximum parallelism? Here mutex is a binary semaphore initialized to 1. Forks are assumed to be numbered from 0 to (N-1). There are a total of N philosophers numbered from 0 to (N-1). …
-1
votes
2 answers

Dining Philosopher Program C

I am working with the classic dining philosopher problem with 5 philosophers and 5 chopsticks. My homework is to use 1 mutex and 5 conditions. I got it working but I don't know why philosopher 1 never eats, but 4,3,0 eat and 2 eats twice. Here's my…
user3335367
  • 435
  • 3
  • 6
  • 9
-1
votes
1 answer

Why is the concurrently-written boolean value still true after being set to false?

I'm writing a Philosophers Dining solution in Go. My solution is simple: check if both forks are available. If so, pick both up. If not, leave both be. However, I'm running into a weird concurrency error, whereby a fork's availability is still true…
user1131435
-1
votes
1 answer

Dining Philosopher Thread and Semaphore

I made a simple GUI that has 5 tables and forks and tried to visualize this famous problem, but I cannot achieve to fully implement. I didn't get the stuck point for my code, if anyone have suggestion for me to solve this problem, any help would be…