Question: Write a multithreaded C program (using the pthread library) that has a single shared resource: a variable named sum and creates three different types
Write a multithreaded C program (using the pthread library) that has a single shared resource: a variable named sum and creates three different types of threads: adder, subtracters and readers. Adders increment the value of sum by 1, subtracters decrement the value of sum by 1 and readers simply print the current value of sum to the console. The adder and subtracter threads will require exclusive access to the sum variable, while multiple reader threads may access the sum variable at once. Your implementation should create a random number of adders, subtracter and reader threads. Your program will need to define an appropriate set of thread entry point functions that implement a system of mutual exclusion and include a main function that creates the threads. State any assumptions that you make about the problem in your answer.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
