Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started