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

Is there a way to simulate multithreading in DOS, e.g., when solving the dining philosopher's problem?

The dining philosophers problem is a classic computer science textbook problem for demonstrating the use of multithreading. As Wikipedia says: Five silent philosophers sit at a round table with bowls of spaghetti. Forks are placed between each pair…
Sep Roland
  • 33,889
  • 7
  • 43
  • 76
1
vote
0 answers

arbiter solution for dining philosopher problem

In the given solution, I have implemented the arbiter solution. My philosopher is picking up any 2 random chopsticks. Before locking these chopsticks, I have used waiter lock. I am unable to get the problem with this solution. I'm still getting…
Ankush K
  • 334
  • 3
  • 13
1
vote
1 answer

Dining philosophers using semaphores (BACI)

I have to solve the dining philosophers problem by using semaphores. In my code every second philosopher is taking a chopstick and the rest are waiting. I still have some errors in the main function. Can you tell me how to initiate Chopstick[k]? I'm…
qorisend
  • 13
  • 2
1
vote
1 answer

Dining-Philosopher's Monitor solution: Does `pickup(i)` need to invoke `self[i].signal()` indirectly?

From Operating System Concepts 5.8.2 Dining-Philosophers Solution Using Monitors Next, we illustrate monitor concepts by presenting a deadlock-free solution to the dining-philosophers problem. This solution imposes the restriction that a…
1
vote
1 answer

C `signal` has too few arguments

I am working on a problem where I am supposed to implement an example of the dining philosopher paradigm. Note: Yes this a homework assignment, before anyone asks. I am not asking for a solution though. I am confused because this Philosopher…
user4780686
1
vote
2 answers

Dining Philosopher's solution ending up in deadlock

I've implemented the resource hierarchy solution to the Dining Philosopher's Problem. When I try to compare the two Chopsticks' n values, they end up in deadlock. However, if I use their hashCodes instead of n values, it runs smoothly. Why this…
msamogh
  • 147
  • 8
1
vote
1 answer

Handling connection pool exhaustion and avoiding deadlock in Hibernate/C3P0

My old application following chain to query my database: Spring Tx -> Hibernate -> C3P0. Now I need to implement new features based on the existing architecture. I normally enter a transactional context by using either the @Transactional annotation…
usr-local-ΕΨΗΕΛΩΝ
  • 26,101
  • 30
  • 154
  • 305
1
vote
1 answer

How to increment the Semaphore value in c++, to solve philosophers dinning

Trying to solve philosophers dinning problem by creating a doorman to only allow 4 philosophers to dine at once, planned on using semaphores for this but there is limited material about them on the web, and i cant figure out how to increment to…
1
vote
1 answer

How to create a totally independent Thread inside another Thread in Java?

I try to implement a client-server software in Java RMI to solve the dining philosophers problem (https://en.wikipedia.org/wiki/Dining_philosophers_problem) as part of my studies. The network has to be able to recognize clients that accidentally…
1
vote
1 answer

Join()ing on multiple threads and handling leaked output

I'm solving a multi-threaded problem in Java and have the core problem itself resolved, but my output isn't what I'd expect. I have a main thread that spins new threads that each perform their tasks. It looks like the following…
Zach
  • 4,555
  • 9
  • 31
  • 52
1
vote
1 answer

How to avoid starvation?

I'm trying to fix my code, I've solved the deadlock an the mutual exclusion problem, but I don't know how I can avoid the starvation, because in promela (PML) there aren't the monitor. Can someone help me? Thanks in advance bool forchetta0 =…
macco
  • 21
  • 1
  • 11
1
vote
2 answers

Dining philosophers in java

Today, I decide to try to solve the dining philosophers problem. So I write the code below. But I think that it is not correct, so I will be pleased if someone tells me what is wrong with it. I use forks for locks ( I only read them, because of that…
DPM
  • 1,540
  • 2
  • 18
  • 40
1
vote
2 answers

Changes made by threads in C++

I'm trying to simulate the Dining Philosophers problem but I'm having trouble visualising it. When the thread moves from Waiting() to Eating() to Thinking() it changes a variable called state to represent this. However in my main thread it never…
Alex L
  • 115
  • 11
1
vote
0 answers

Dining philosophers using the resource hierarchy solution

So the problem with this solution, as I've understood it, is that it's too time consuming. In the explanation I was reading and also on wikipedia it's assumed that philosopher #1 has both forks #3 and #5. But now he also needs fork #2, so he drops…
1
vote
1 answer

Putting a semaphore in shared memory C

I am trying to make a semaphore visible to multiple processes after forking. This is the dining philosopher's problem using shared memory and a semaphore to ensure only one philosopher picks up chopsticks at a time (not the most efficient way, an…
CodeMonkey
  • 268
  • 5
  • 16