Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 10 (1 point) Read the following C program that uses the Pthreads API. What would be the output from the program at LINE A
Question 10 (1 point)
Read the following C program that uses the Pthreads API. What would be the output from the program at LINE A and LINE B?
#include#include #include #include int value= 0: void* runner(void*param); /* the thread*/ int main(int argc, char argv[]) { pid t pid; pthread_t tid; pthread_attr_t attr; pid = fork(): if (pid == 0){/* child process */ pthread attr_init(&attr); pthread_create(&tid, &attr, runner, NULL); pthread_join(tid, NULL); printf("CHILD: value- %d ", value value): /* LINE A*/ } else if (pid > 0){ /* parent process*/ wait(NULL); printf("PARENT:value = %d ", value); /*LINE B */ } } void runner(void *param){ value 10; pthread_exit(0); }
a) Output at LINE A is 0
Output at LINE B is 0
b) Output at LINE A is 10
Output at LINE B is 0
c) Output at LINE A IS 10
Output at LINE B is 10
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started