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

How to solve Dining Philosophers with Mutex in Java?

My java project has 3 java class. There is Main,Philosoper and chStick. I solved Dining Philosophers Problem with using boolean value isTaken. in the project chStick.java like below. This class control that chopstick in use or not use. class…
Yakup
  • 3
  • 3
-2
votes
1 answer

How is this solution for dining philosophers problem (dpp) working? Mutex and semaphores

I am trying to solve the dining philosophers problem (the problem: https://en.wikipedia.org/wiki/Dining_philosophers_problem) and I found the solution with code below. Solution uses semaphores and one mutex. I implemented busy waiting simple…
-3
votes
1 answer

Dining philosophers problem in Go fails unit test

I'm taking a Go course, that has an assignment as follows: Implement the dining philosopher's problem with the following constraints/modifications. There should be 5 philosophers sharing chopsticks, with one chopstick between each adjacent pair…
Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219
-4
votes
1 answer

locking at same time vs one by one Dining philosphers

What is the difference between locking at same time vs one by one in dining philospher that is lock(lck1, lck2) vs lck1.lock() lck2.lock() ? I have tried both of them they are working fine. I have read about lock(lck1, lck2) this way we can prevent…
AKASH
  • 33
  • 7
-5
votes
1 answer

Dining philosophers Java

I got a school assignment today to simulate the dining philosophers problem. I just made this code to test if it worked this easy way (A). The problem I am having right now is that when someone that is not supposed to be eating starts to eat…
-9
votes
2 answers

Can anyone help me my code when i run, it give this error : Segmentation fault here is my code

/* This program consists of 12 functions named, philosopher(), setPhilosopher(), * take_Forks(), put_Forks(), downPhilosopher(), writeFile(), thinking(), test(), setState(), * readFile(), eating(),argNo, and main(). It allows a philosopher to…
1 2 3 4 5 6
7