Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Dining Philosophers Problem: N philosophers are sitting at a round table. In the center of the table, there is a bowl of rice.

image

The Dining Philosophers Problem: N philosophers are sitting at a round table. In the center of the table, there is a bowl of rice. Between each pair of philosopher is a single chopstick. A philosopher is in one of three states: thinking, hungry and eating. At various times a thinking philosopher gets hungry. A hungry philosopher attempts to pick up one of the adjacent chopsticks, then the other one (not both at the same time). If the philosopher is able to obtain the pair of chopsticks, then the philosopher eats for a period of time. After eating, the philosopher puts the chopsticks down and returns thinking. In this project, you are supposed to write a C program for the dining philosopher problem, which will implement a deadlock-free solution with maximum concurrency. The program should work for any number of philosophers (odd numbers, maximum 27). In the program, a thread will express a philosopher. These threads will be spawned by the main thread, which is not a philosopher. You need to use Pthreads, mutex and condition variables to synchronize. You can use monitor based solutions or semaphores that are deadlock free. The program will be named phsp and will take the following arguments: php For the arguments; is the minimum thinking time for a philosopher, is the maximum thinking time; is the minimum dining time, is the maximum dining time. Use miliseconds as unit. The highest value that these parameters can take is 60seconds and lowest value that these parameters can take is 1ms. is the distribution and it can be either "uniform" or "exponential". The mean parameters for exponential distributions are (min think+max think)/2 or (min dine+max.dine)/2. The thinking time and dining time for a philosopher will be selected randomly according to the specified dst, and the mean value. For exponential distribution; simply generate a random value with exponential distribution, and if the value is not in range, repeat it. Each philosopher will dine times. The program should terminate after all of the philosophers complete dining (num times). A sample initiation could be: phsp 5 500 1000 50 100 exponential 100

Step by Step Solution

3.25 Rating (163 Votes )

There are 3 Steps involved in it

Step: 1

Heres a C program implementing a deadlockfree solution for the Dining Philosophers Problem using Pthreads mutex and condition variables The program al... 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_2

Step: 3

blur-text-image_3

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

Computer Organization and Design The Hardware Software Interface

Authors: David A. Patterson, John L. Hennessy

5th edition

124077269, 978-0124077263

More Books

Students also viewed these Programming questions