Dining Philosopher Problem (Please use skeleton code)
Task 1 Eliminate the deadlock by a...
![subject](/tpl/images/cats/User.png)
Engineering, 15.04.2020 20:49 christinavelez26
Dining Philosopher Problem (Please use skeleton code)
Task 1 Eliminate the deadlock by avoiding circular waiting. (Hint: change the order to access chopsticks for some philosophers.)
Task 2 Eliminate the deadlock by avoiding hold and wait. In other words, if a philosopher is not able to obtain the right chopstick, he/she will release the left chopstick immediately. (Hint: Use Pthread Mutex to solve the problem.)
Please provide a source program for each task, like task.1 & task.2
skeleton code ( In C):
#include
#include
#include
#include
#include
#define NUMP 5
pthread_mutex_t fork_mutex[NUMP];
int main(int argc, char* argv[])
{
int i;
pthread_t diner_thread[NUMP];
int dn[NUMP];
void *diner();
for (i=0;i
pthread_mutex_init(&fork_mutex[ i], NULL);
for (i=0;i
dn[i] = i;
pthread_create(&diner_thread[i] ,NULL, diner,&dn[i]);
}
for (i=0;i
pthread_join(diner_thread[i],NULL);
pthread_exit(0);
}
void *diner(int *i)
{
int v;
int eating = 0;
printf("I'm diner %d\n",*i);
v = *i;
while (eating < 5) {
printf("%d is thinking\n", v);
sleep( v/2);
printf("%d is hungry\n", v);
pthread_mutex_lock(&fork_mutex[ v]);
pthread_mutex_lock(&fork_mutex[ (v+1)%NUMP]);
printf("%d is eating\n", v);
eating++;
sleep(1);
printf("%d is done eating\n", v);
pthread_mutex_unlock(&fork_mute x[(v+1)%NUMP]);
pthread_mutex_unlock(&fork_mute x[v]);
}
pthread_exit(NULL);
Expert
![ansver](/tpl/images/cats/User.png)
Answers: 1
![](/tpl/images/ask_question.png)
![](/tpl/images/ask_question_mob.png)
Another question on Engineering
![question](/tpl/images/cats/User.png)
Engineering, 04.07.2019 18:10
True or false (explain) (110)[111] is a slip system in bcc metals . the {111} family in fcc contains 8 planes. resolved shear stress (rss) in single crystals is just related to the applied stress. critical resolved shear stress (crss) in single crystal metals is direct proportional to the number of defects in the structure
Answers: 2
![question](/tpl/images/cats/User.png)
Engineering, 04.07.2019 18:20
Derive the correction factor formula for conical nozzle i=-(1+ cosa) and calculate the nozzle angle correction factor for a nozzle whose divergence hal-fangle is 13 (hint: assume that all the mass flow originates at the apex of the cone.
Answers: 3
![question](/tpl/images/cats/User.png)
Engineering, 04.07.2019 18:20
An open feedwater heater operates at steady state with liquid entering at inlet 1 with t? = 40Β°c and pl = 1 .2 mpa. water vapor att2-200Β°c and p2 = 1.2 mpa enters at inlet 2. saturated liquid water exits with a pressure of pa 1.2 mpa. neglect heat transfer with the surroundings and all kinetic and potential energy effects, determine the mass flow rate of steam at inlet 2 if the mass flow rate of liquid water at inlet 1 is given as 2 kg/s.
Answers: 3
![question](/tpl/images/cats/User.png)
Engineering, 04.07.2019 19:10
Asteel wire of 2 mm diameter is fixed between two points located 2 m apart. the tensile force in the wire is 250n, if its density of steel is given by 7830 kg/m3 the fundamental frequency of vibration hz? ?
Answers: 3
You know the right answer?
Questions
![question](/tpl/images/cats/obshestvoznanie.png)
Social Studies, 09.06.2021 01:00
![question](/tpl/images/cats/en.png)
English, 09.06.2021 01:00
![question](/tpl/images/cats/mat.png)
Mathematics, 09.06.2021 01:00
![question](/tpl/images/cats/mat.png)
Mathematics, 09.06.2021 01:00
![question](/tpl/images/cats/mat.png)
Mathematics, 09.06.2021 01:00
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/istoriya.png)
![question](/tpl/images/cats/en.png)
![question](/tpl/images/cats/biologiya.png)
Biology, 09.06.2021 01:00
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/himiya.png)
![question](/tpl/images/cats/fizika.png)
![question](/tpl/images/cats/ekonomika.png)
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/mat.png)
Mathematics, 09.06.2021 01:00
![question](/tpl/images/cats/mat.png)
Mathematics, 09.06.2021 01:00
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/mat.png)
Mathematics, 09.06.2021 01:00
![question](/tpl/images/cats/biologiya.png)
Biology, 09.06.2021 01:00