Starting from:

$30

CSE330-Project 5 Dining Philosophers Problem Solved

Using the semaphores you have implemented, detect deadlocks in Dining Philosophers problem. 

 

2.Test case:

The first line of the test case contains two numbers

A,B

A is the number of philosophers, and B is the number of entries coming after the first line

The number of chopsticks is the same as number of philosophers

Your program should have an array of semaphores where each semaphore (each element of the array) corresponds to each chopstick. 

Each philosopher gets access to “the right” chopstick by doing 

P(Sem[(philosopher ID – 1)% (number of Chopsticks)])

Then yields to the next philosopher

When the philosopher comes back the philosopher attempts to access “the left” chopstick by doing

P(Sem[philosopher ID % (number of Chopsticks) ]) 

Then yields to the next philosopher

When it comes back it prints

Printf(“\n Philosopher %d is eating \n”, philosopher ID); 

Then it releases the right chopstick by doing

V(Sem[(philosopher ID – 1)% (number of Chopsticks)])

Then it releases the left chopstick by doing

V(Sem[(philosopher ID)% (number of Chopsticks)])

Then it deletes itself from the readyQ.

Then it yields to the next philosopher

 

 

The next B lines has philosopher numbers in order to populate the Ready Queue.

The program starts with the first element of the Ready Queue.

 

Test case example

4,2

1

3

Output

Philosopher 1 is eating

Philosopher 3 is eating

 

Test case example 2

4,2

1

2

Output

Philosopher 2 is eating

Philosopher 1 is eating

More products