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 19:00
In he example code, what does the title attribute create? a tool tip an element a source a markup
Answers: 1
Computers and Technology, 23.06.2019 22:40
22. sata3 allows for data transfer rates of 600 mb/s. explain why you would likely not be able to copy data from one hard drive to another at anywhere close to this speed. also, what could be upgraded on the computer to achieve transfer speeds closer to 600 mb/s
Answers: 1
Computers and Technology, 24.06.2019 07:00
Guys do you know sh27 cause he hacked me : ( pidgegunderson my old user
Answers: 2
Computers and Technology, 24.06.2019 13:30
Which type of excel chart should be used to track students’ progress on test grades? line column bar pie
Answers: 2
Using this Skeleton Code, what is the correct code to run the dining philosophers program?
Mathematics, 09.11.2020 20:50
English, 09.11.2020 20:50
History, 09.11.2020 20:50
Engineering, 09.11.2020 20:50
Arts, 09.11.2020 20:50
Mathematics, 09.11.2020 20:50
History, 09.11.2020 20:50
History, 09.11.2020 20:50