Computers and Technology, 09.04.2020 22:03 GladToBeACarmine
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);
}
Answers: 2
Computers and Technology, 22.06.2019 01:00
What is added to the < meta > tag to describe the encoding type?
Answers: 2
Computers and Technology, 22.06.2019 07:30
In the film "epic 2015," epic is the name for:
Answers: 3
Computers and Technology, 22.06.2019 15:30
To increase sales, robert sends out a newsletter to his customers each month, letting them know about new products and ways in which to use them. in order to protect his customers' privacy, he uses this field when addressing his e-mail. attach bcc forward to
Answers: 2
Computers and Technology, 22.06.2019 17:00
Annie is creating a corporate report for a company’s annual meeting. in the report, she wants to add the signature of various department heads. which device can annie use to capture signatures to include in the report? a. printer b. monitor c. e-reader d. digitizing tablet
Answers: 1
Using this Skeleton Code, what is the correct code to run the dining philosophers program?
Mathematics, 05.03.2021 08:00
English, 05.03.2021 08:00
Health, 05.03.2021 08:00
English, 05.03.2021 08:00
English, 05.03.2021 08:00
Social Studies, 05.03.2021 08:00
Chemistry, 05.03.2021 08:00
History, 05.03.2021 08:00
English, 05.03.2021 08:00
Social Studies, 05.03.2021 08:00
Biology, 05.03.2021 08:00
English, 05.03.2021 08:00
History, 05.03.2021 08:00