Question: uestion 3: [5 marks Study the following code and give the output. Assume that processes run in the order they are created (parent before child).

 uestion 3: [5 marks Study the following code and give the

uestion 3: [5 marks Study the following code and give the output. Assume that processes run in the order they are created (parent before child). (Show your working as brief comments) #include #include #include #include #include static int sum = 0; pthread_mutex_t mutex; void *func ) t pthread mutex lock (&mutex); sum++i printf("%d ", sum); pthread mutex unlock (&mutex); int main(void) \ pid t pid - fork int numthreads; if (pid0 numthreads 3; else numthreads 2 pthread_t tid[numthreads]; //thread id array printf("%d ", sum); int i; for (i- 0; i

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!