Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Dining Philosopher's problem is a famous problem in OS. A deadlock may happen when all philosophers want to start eating at the same time and

image text in transcribed
image text in transcribed
Dining Philosopher's problem is a famous problem in OS. A deadlock may happen when all philosophers want to start eating at the same time and pick up one chopstick and wait for the other chopstick. We can use semaphores to simulate the availability of chopsticks. To prevent the deadlock, in class we have discussed three solutions: 1. 2. 3. Allow at most 4 philosophers to be sitting simultancously at the table Allow a philosopher to pick up her chopsticks only if both are available Use an asymmetric solution: an odd-numbered philosopher picks up first the left chopstick and then the right chopstick. Even-numbered philosopher picks up first the right chopstick and then the left chopstick. The following program can lead to a deadlock. Run the program and observe the deadlock condition. Based on the program, please implement the above three solutions to prevent the deadlock. Each solution should be saved as an individual C program (e.g. solutionl.c, solution2.c, and solution3.c). Include necessary comments in your programs. Submission: solution2.c and solution3.c on Blackboard # i nclude # include # include #define N 5 //the number of philosophers sem t SINI //semaphores for chopsticks void philospher (void num) void take_chopsticks (int)i void put_chopsticks (int) int phil num[N]-10,1,2,3,41a 1/philosophe: ID int main) int i: pthread t thread idIN] for (i-RN:1++) sem init(&sIi.0.1) pthread create (&threadidi),NULL philospher, Sphil num[i]) pthread join(thread idA].NULL) for {i-0; i<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

T Sql Fundamentals

Authors: Itzik Ben Gan

4th Edition

0138102104, 978-0138102104

More Books

Students also viewed these Databases questions