Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions