Question: 1#include 2 #include 3 4 int value = 0; 5 void *runner(void *param); /* the thread */ 6 7 int main(int argc, char *argv[]) 8

1#include

2 #include

3 4 int value = 0;

5 void *runner(void *param); /* the thread */

6

7 int main(int argc, char *argv[])

8 {

9 pthread_t tid; /* the thread identifier */

10 pthread_attr_t attr; /* set of attributes for the thread */

11 int pid;

12

13 value = value + 2;

14

15 pid = fork();

16

17 if(pid == 0) { /* child process */

18 pthread_attr_init(&attr);

19 pthread_create(&tid,&attr,runner,argv[1]);

20 pthread_join(tid,NULL);

21 printf("CHILD: value = %d", value); /* LINE C */

22 }

23 else if (pid > 0) { /* parent process */

24 wait(NULL);

25 printf("PARENT: value = %d", value); /* LINE P */

26 }

27 }

28

29 void *runner(void *param) {

30 value = value + 6;

31 pthread_exit(0);

32 }

The above program uses the Pthreads API. What would be the output from the program at LINE C and LINE P (10 points)? Explain your answer (15 points)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!