CSE330 Homework 5-Dining Philosophers Solved

30.00 $ 15.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . zip solution files instantly, after Payment

Description

5/5 - (1 vote)

1.Dining Philosophers Problem:

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

 

Your project must consist of 5 files

 

  1. h (uses ucontext.h)

 

  1. h (includes TCB.h)

 

  1. h (includes q.h)

 

  1. h (includes threads.h) if you have written one.

 

  1. proj-5.c (includes threads.h)

(make sure the compile command, “gcc proj-5.c” does the correct compilation).

 

All 5 files are to be ZIPPED into one zip file and uploaded in Canvas. The name of this file should reflect the name of the student (abbreviated, do not make it too long).

 

Note: Grading is on Ubuntu. It is in your interest to make sure the program compiles and runs in the target test platform.

 

 

Testing your code on grading test cases

Grading test cases are different from the test cases provided.

To test your code against grading testcases follow these steps:

 

Put the four files q.h tcb.h threads.h and proj-5.c in one zip file and name the file  YOUR LAST NAMEProject5.zip (no gaps)

 

Make sure you do not have a folder inside your zip. When we unzip we should only have the files not a folder.

 

For example BanerjeeProject5.zip

 

  • Homework5-repn0p.zip