Question: 1 . Control access to a shared variable: ( 3 0 points ) Download the thread - based application file ( P 1 . c

1. Control access to a shared variable: (30 points) Download the thread-based application file (P1.c). The application creates 2 threads: one increments the global variable someValue a number of times (COUNT), and another decrements someValue the same number of times. Compile and run P1.c and answer the following questions: a. What should the final value for someValue be? What does the program print as the final value for someValue? b. Increment COUNT to 100,1000,10000, and compile and run the code. In each case, what does the program print as the final value for someValue? Explain the reason behind the discrepancy in the output. c. Update the code to solve the problem.

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 Programming Questions!