subject

Using this Skeleton Code, what is the correct code to run the dining philosophers program?

#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);

}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 22:30
Type the correct answer in the box. spell all words correctly.what kind of graph or chart does this image represent? the given image represents a (blank).
Answers: 2
question
Computers and Technology, 22.06.2019 22:40
When you type the pwd command, you notice that your current location on the linux filesystem is the /usr/local directory. answer the following questions, assuming that your current directory is /usr/local for each question. a. which command could you use to change to the /usr directory using an absolute pathname? b. which command could you use to change to the /usr directory using a relative pathname? c. which command could you use to change to the /usr/local/share/info directory using an absolute pathname? d. which command could you use to change to the /usr/local/share/info directory using a relative pathname? e. which command could you use to change to the /etc directory using an absolute pathname? f. which command could you use to change to the /etc directory using a relative pathname?
Answers: 3
question
Computers and Technology, 24.06.2019 02:30
Write the pseudo code for this problem based on what you learned from the video. the purpose is to design a modular program that asks the user to enter a distance in kilometers, and then converts that distance to miles. the conversion formula is as follows: miles = kilometers x 0.6214
Answers: 3
question
Computers and Technology, 24.06.2019 03:30
Other - a written response, no less than arial 12-point font, to the following: of the following, which would you consider is most important to customer service goals? choose one and explain why. (1) accuracy (2) punctuality and attendance (3) courtesy (4) productivity (5) organization
Answers: 1
You know the right answer?
Using this Skeleton Code, what is the correct code to run the dining philosophers program?
Questions
question
Mathematics, 15.10.2019 16:20
question
Mathematics, 15.10.2019 16:20
Questions on the website: 13722360