Write a multithreaded C program (using the pthread library) that has a single shared resource: a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Related Book For
Managerial accounting
ISBN: 978-0471467854
1st edition
Authors: ramji balakrishnan, k. s i varamakrishnan, Geoffrey b. sprin
Posted Date:
Students also viewed these programming questions
-
Microkernel operating systems aim to address perceived modularity and reliability issues in traditional "monolithic" operating systems. (i) Describe the typical architecture of a microkernel...
-
do the following,..... Write program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. Create program that takes in user input...
-
You are asked to evaluate the following two projects for Boring Corporation using the NPV method combined with the PI approach, which project would you select? Use a discount rate of 10 percent....
-
A ferryboat is traveling in a direction 38.0o north of east with a speed of 5.50 m/s relative to the water. A passenger is walking with a velocity of 2.50 m/s due east relative to the boat. What is...
-
Sally hires a maid to work in her home for $260 per month. The maid is 25 years old and not related to Sally. During 2016, the maid worked 10 months for Sally. a. What is the amount of Social...
-
1. To develop an understanding of your ethical leadership style 2. To understand how your preferred ethical leadership style relates to other ethical leadership styles Directions 1. Please read the...
-
Rosenthal Company manufactures bowling balls through two processes: Molding and Packaging. In the Molding Department, the urethane, rubber, plastics, and other materials are molded into bowling...
-
17.13 Let g be holomorphic in C and assume there exists a finite constant M such that |g(z)| M|sin z (z C). z| Prove that g(z) = K sinz on C, for some constant K with |K| M. (Hint: consider g(z)/sin...
-
One way to see whether this procedure will be successful is to split the original data set into two subsets: one subset for estimation and one subset for validation. A regression equation is...
-
Consider the method Yk+1 = Yk + h [af(yk) + 3f(yk+1)] dy =f(y). Find constants dx for numerically solving autonomous differential equations a, 3ER that yield the smallest local truncation error. You...
-
In bread making, combining ingredients all at once, mixing to develop gluten, fermenting once or twice then proceeding with standard make-up procedures is known as Question 1 options: sour-dough...
-
Provide a calculation example for each of the following: o Patient's co-payment insurance portion = full reimbursement o Patient's co-insurance insurance portion = full reimbursement
-
What must all enrollees in TRICARE for Life do? Multiple Choice be eligible for Medicare Part A only be eligible for Medicare Part B only have Part A premiums deducted from their Social Security...
-
The Subotnick Financial Services Center at Baruch includes a replica of a trading floor. True False
-
Who is a disadvantage of a finger scanner? Question 2 Select one: a. They are not accurate b. Not covered by insurance c. Both A & B d. None of the above
-
6. A windmill with a rotor diameter of 50 m converts the wind energy into electrical energy with an efficiency of 25%. The cut-in and cut-out speed are 10 km / h and 90 km / h, respectively. What is...
-
Integration is a vital concept when applied in one?s life. Integrating your life means making ideal choices. Perfect choices on the other go in line with quality decisions. Quality decisions lead to...
-
Is it always advisable to accept projects with the highest (positive) NPVs? IRRs? Why or why not?
-
Worthington Company employs a job-order costing system. Before disposition of the underapplied or overapplied over head, selected year-end balances from Worthingtons accounting records were: Cost of...
-
The Jogirushi Company makes a line of premium rice cookers, specially designed for the Japanese market. In February, Jogirushi launched a new model that is exclusively made in its Osaka factory. The...
-
Why do you and your business need to be able to communicate well?
-
What are the basic criteria for effective messages?
-
What are the questions for analyzing a business communication situation?
Study smarter with the SolutionInn App