Question: (15) Consider the following UNIX C program (Program B) //THREADED PROGRAM //To compile: g+ -lpthread //To Run: ./a.out #include #include #include #include #include #include int

 (15) Consider the following UNIX C program (Program B) //THREADED PROGRAM

(15) Consider the following UNIX C program (Program B) //THREADED PROGRAM //To compile: g+ -lpthread //To Run: ./a.out #include #include #include #include #include #include int sum= 0; void* grandChild (void *ptr)sum++; void *child( void *ptr ) f pthread.t thread; pthreadcreate(&thread , NULL, grandChild, (void*)NULL) pthreadjoin (thread, NULL); sum+-+; int main (void) -f sum+-+; pthread.t thread; pthread-create(&thread, NULL, child , (void *)NULL) pthread-join (thread, NULL); printf("SUM : % n", sum ) ; return 0; (a) Give the output from the above program (b) How may threads are created? (c) What is the reason for the difference in the sum variable between Program A and Program B

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!