Question: Writing the code in C language, the program is in the objective also there's information about which solution to use . AND SHOW OUTPUT!! Objnetives
Objnetives Write a program to simulate the Dinning Philosophers Problem with random waiting time per philosopher. modify the problem by making the philosopher wait for a random amount of time instead of same time after failing to acquire right hand fork THEORY Five philosophers are seated around a circular table. Each philosopher has a place of spaghetti and he need two forks to eat. Between each plate there is a fork. The life of a philosopher consists of alternate period of eating& thinking. When a philosopher gets hungry he tries to acquire his left fork, if he gets it, it tries to acquire right fork In this solution, we check after picking the left fork whether the right fork is available or not If not, then philosopher puts down the left fork & continues to think. Even this can fail if all the philosophers pick the left fork simultaneously & no right forks available &putting the lef fork down again. This repeats& leads to starvation. Now, we can modify the problem by making the philosopher wait for a random amount of time instead of same time after failing to acquire right hand fork. This will reduce the problem of starvatkn VAR me: semaphore, initially 1: s[5]: semaphore s|5]. initially 0 pflagl5]: (THINK, HUNGRY, EAT, initially THINK: philosopher flag * for mutual exclusion As before, each philosopher is an endless cycle of thinking and eating procedure philosopheri) while TRUE do THINKING take chopsticksi) EATING drop chopsticks()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
