2. Given the following producer&consumer problem solution, what is the potential risk in the code when...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
2. Given the following producer&consumer problem solution, what is the potential risk in the code when the solution is running on a single CPU, multitasking operating system? Assume we need run multiple producers and consumers at the same time, modify the code to remove the risk using any solution that is proper. (10 pt) Producer: while (true) { } /* produce an item and put in nextProduced */ BUFFER_SIZE) while (count Consumer: while (true) { } == ; // do nothing buffer [in] = nextProduced; in = (in + 1) % BUFFER_SIZE; count++; while (count = 0) ; // do nothing = nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; count--; /* consume the item in nextConsumed 2. Given the following producer&consumer problem solution, what is the potential risk in the code when the solution is running on a single CPU, multitasking operating system? Assume we need run multiple producers and consumers at the same time, modify the code to remove the risk using any solution that is proper. (10 pt) Producer: while (true) { } /* produce an item and put in nextProduced */ BUFFER_SIZE) while (count Consumer: while (true) { } == ; // do nothing buffer [in] = nextProduced; in = (in + 1) % BUFFER_SIZE; count++; while (count = 0) ; // do nothing = nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; count--; /* consume the item in nextConsumed
Expert Answer:
Answer rating: 100% (QA)
The code has a potential risk of race conditions when running on a single CPU multit... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
"internet radios" for streaming audio, and personal video recorders and players. Describe design and evaluation processes that could be used by a start-up company to improve the usability of such...
-
In what respects did certain employees regard the University of Baths culture under Breakwell as falling short of the aspirations described in the 2016-21 strategic plan?
-
In the Monopoly Millionaires' Club lottery game, you pay $5 and select five different numbers between 1 and 52, and then a sixth number between 1 and 28 is randomly assigned to you. Winning requires...
-
Water is run through a hydraulic turbine at a rate of 11,500 L/min from a 160-m-high reservoir and produces 250 kW of shaft power. What is the efficiency of this turbine?
-
Explain several implications of IFRS on financial reporting by health care organizations.
-
Greene Corporation has four divisions: the assembly division, the processing division, the machining division, and the packing division. All four divisions are under the control of the vice president...
-
Oxygen gas having a volume of 1250 cm 3 at 43.1 C and 1.04 x 10 5 Pa expands until its volume is 1900 cm 3 and its press is 1.08 x 10 5 Pa. Find: (a) the number of moles of oxygen present and (b) the...
-
Based on the information in Table 4-2, the inventory turnover ratio is Table 4-2 Assets: Cash and marketable securities Accounts receivable Inventories Prepaid expenses Total current assets Fixed...
-
This reflection activity is comprised of two sections collectively totaling a minimum of 500 words. Complete your reflections by responding to all prompts. Reflect on the following in a minimum of...
-
1. Explain how the Philippines developed as an event/MICE destination? 2. How do you think the Philippines compares with its neighboring countries in Southeast Asia in terms of developments in the...
-
Read the articles "MarketLine Industry Profile: IT Services in South Africa" and "MarketLine Report: ACER Incorporated." Watch the video "Overwhelmed" by the artist Big Daddy Weave. This video is...
-
Relevant Costs for Equipment Replacement Decision Health Scan, Inc. paid $50,000 for X-ray equipment four years ago. The equipment was expected to have a useful life of 10 years from the date of...
-
https://www.bbc.comews/business-40945709 this article is titled - how jeans giant Levi Strauss got it's mojo back. please read the article before answering the questions, answer in full detailed...
-
Focus on the short term: If A, an entertainer, were averaging $1 million a year of taxable income from his business, would you advise A to incorporate as a device to save taxes? Would you advise A to...
-
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...
-
What if you were asked to give an everyday example that demonstrates the principles discussed in this chapter? (Would sipping a teaspoon of Tabasco or other hot sauce be one?)
-
For the catalytic reaction A cat C + D the rate law can be written as rA=kCA(1+KACA)2 Which will predict the highest conversion, the maximum mixedness model or the segregation model? Specify the...
-
Go to the five LearnChemE screencasts link for Chapter 5 (http://www.umich.edu/~elements/6e/05chap/learn-cheme-videos.html). 1. In the screencast of the PBR with pressure drop, is there a problem...
-
A dump truck, whose bed is made of steel, holds an old steel watering trough. The bed of the truck is slowly raised until the trough begins to slide. What is the acceleration of the trough as it...
-
A vendor at the local art fair ties her tent to the concrete-filled coffee can shown in Figure P5.34. A stiff breeze comes up and the string becomes taut. What is the maximum value that the string...
-
The acceleration of the spacecraft in which the Apollo astronauts took off from the moon was 3.4 m/s 2 . On the moon, g = 1.6 m/s 2 .What was the apparent weight of a 75 kg astronaut during takeoff?
Study smarter with the SolutionInn App