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

Deadlocks in C with semaphores

I have an assignment about deadlocks for a Dining Philosophers program. I am asked to make a file called "sections1.c" that has a deadlock issue and after completing creating a deadlock, I am to copy the code and solve the deadlock condition in a…
2
votes
1 answer

Using condition_variable::notify_all to notify multiple threads

I have been trying to code the dining philosophers as a way to get better with multithreading programming. In my code, I have a condition_variable that stops the thread until all the threads have been created. However, it seems that when I call…
Aryan
  • 608
  • 6
  • 15
2
votes
0 answers

Modified dining philosophers with semaphores

In this modified version of the dining philosophers problem, a philosopher may use any of the forks available, not just those on his left and right. Given the following solution to the original problem using semaphores system…
user6269144
  • 318
  • 1
  • 10
2
votes
2 answers

Dining philosophers in java using semaphores

I want to solve dining philosophers problem using java semaphores but I'm stuck. Highest id chopstick should be available but it seems to be always taken and i don't know why. Can anyone tell me where I made mistake? Fork class: class Fork { public…
Taylor Nicol
  • 23
  • 1
  • 4
2
votes
1 answer

My Five Philosophers are all eating at the same time, why?

This is the class philosopher public class Filosofo implements Runnable{ public String nome = null; public static Bacchetta[] bacchette = new Bacchetta[5]; //this should be the resource public Bacchetta bacchettaDX; //right resource …
2
votes
1 answer

Making an array of ints visible to child processes using mmap

I am working on the dining philosopher's problem and can't use threads so I need to use shared memory to make the array of chopsticks and philosophers visible to all child processes. I am trying to use mmap, however, my use of mmap is incorrect and…
CodeMonkey
  • 268
  • 5
  • 16
2
votes
1 answer

Simple dining philosopher using pthreads

I am working on the dining philosophers program. However I am running into a problem that my program stops before all of the philosophers have eaten, and I don't understand why. This is my code as of…
user3335367
  • 435
  • 3
  • 6
  • 9
2
votes
2 answers

Why is the left / right sequence important in conductor solution to philosophers dinner?

The conductor solution to the philosopher dinner problem as described suggest that a semphore of size four be used and that all philosophers attempt to get left fork before right fork.…
2
votes
1 answer

Conductor solution to philosophers dinner

The conductor solution to the philosopher dinner problem as described suggest that a semphore of size four be used and that all philosophers attempt to get left fork before right…
More Than Five
  • 9,959
  • 21
  • 77
  • 127
1
vote
1 answer

Golang implementation of dining philosophers variant problem

I would like to implement a variant of the classical dining philosophers problem which has the definition as: Implement the dining philosopher’s problem with the following constraints/modifications. There should be 5 philosophers sharing…
1
vote
3 answers

Dining Philosophers multiThreaded does not end

I am trying to solve the dining philosophers problem using mutex locks in python import threading import time chopstick_a = threading.Lock() chopstick_b = threading.Lock() chopstick_c = threading.Lock() sushi_count = 500 def philosopher(name,…
1
vote
2 answers

Dynamic Memory allocation of array inside structure in C

I'm doing dining-philosopher problem in C for assignment. And got stuck very begining of my code. I decided each philosopher to be structure, and forks to be int array. But I can't use global variable in this assignment. So, I have to include shared…
acho
  • 53
  • 7
1
vote
1 answer

why dosen't sem_wait() function block even when sem_t value is zero?

I'm trying to implement a simple solution for Dining philosophers problem (with five philosophers) and my solution is based on this logic : sem_t S[philosophers_number] for each philosopher { while(TRUE) { if(current philosopher…
hanie
  • 1,863
  • 3
  • 9
  • 19
1
vote
0 answers

Dining Philosophers starvation problem using mutex locks

The solution provided here for the dining philosopher problem states that: A philosopher must be allowed to pick up the chopsticks only if both the left and right chopsticks are available. I am using the following code for that solution. However,…
seraabrj
  • 13
  • 3
1
vote
1 answer

Deadlock in dining philosophers with channels from Ben Ari?

In Ben Ari's Principles of Concurrent and Distributed Programming (2nd ed.), chapter 8.4, The dining philosophers with channels, they propose a solution which I think might lead to deadlock. Suppose a philosopher 3 takes fork 3. The philosopher must…
89f3a1c
  • 1,430
  • 1
  • 14
  • 24