Question: Part II: [ 5 0 % ] A ) [ 2 5 % ] Write a C program which creates 1 0 threads ( besides

Part II: [50%]
A)[25%] Write a C program which creates 10 threads (besides the main thread). Each thread
increments a shared counter by one 100,000 times. Compile and run your program several times
(at least 5 runs are recommended). Provide screenshots of the output from multiple runs. Discuss
briefly in your report why the final counter value is not consistently 1,000,000 as expected.
B)[25%]: Modify your program from Part II-A to incorporate a mutex lock for synchronizing
access to the shared counter. Ensure that each increment operation on the counter is protected by
the mutex. Capture screenshots showing that the issue identified in Part II-A is no longer
present. In your report, explain how the mutex lock solved 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!