Question: Write a program in C which you create 2 thread s and pass 1/2 to the thread as a parameter. In the thread function, print

Write a program in C which you create 2 threads and pass 1/2 to the thread as a parameter. In the threadfunction, print the value of the parameter passed 10 times. Have a global variable initialised to 0. In the thread function, increment this counter and print the value of the tid and counter value 10 times. Check the counter value printed from the threads. Is there any inconsistency in the value or is the output as you expected? Experiment the same by adding a mutex around the critical section of incrementing the counter. Print the values and check if there is any difference in output. Is there inconsistency in values? What is needed if we want to ensure that the value of the counter must be printed in a certain order?

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!