Consider the program constructs and code snippets for the producer and consumer processes which communicate using...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider the program constructs and code snippets for the producer and consumer processes which communicate using share memory. Provide answers to the questions which follow. #define BUF_SIZE 10 typedef struct { int x = 4; char grade = 'A'; } item; Consumer Remove() while (true) { while (counter == 0) ; // do nothing // remove an item from the buffer item nextConsumed = buffer[out]; out (out + 1) % BUF_SIZE; counter--; } item buffer[BUF_SIZE]; int in = 0, out = 0, counter = 0; //Function nextProduced() creates a new item. Producer insert() while (true) { /* Produce an item */ while (counter == BUF_SIZE) ; // do nothing (keep looping) buffer[in] =nextProduced(); in = (in + 1) % BUF_SIZE; counter++ } (a) (b) (c) After the processes have executed for some time, it is found that out = 9 and in = 6. How many items are in the buffer? Make a sketch to show the position of the items in the buffer. Justify your answer. When in = out = 5, the buffer is found to be empty. Describe a sequence of events which resulted in this configuration. With reference to the code, explain what happens when in = out = 5, the buffer is empty and it's the consumer's turn to execute. Consider the program constructs and code snippets for the producer and consumer processes which communicate using share memory. Provide answers to the questions which follow. #define BUF_SIZE 10 typedef struct { int x = 4; char grade = 'A'; } item; Consumer Remove() while (true) { while (counter == 0) ; // do nothing // remove an item from the buffer item nextConsumed = buffer[out]; out (out + 1) % BUF_SIZE; counter--; } item buffer[BUF_SIZE]; int in = 0, out = 0, counter = 0; //Function nextProduced() creates a new item. Producer insert() while (true) { /* Produce an item */ while (counter == BUF_SIZE) ; // do nothing (keep looping) buffer[in] =nextProduced(); in = (in + 1) % BUF_SIZE; counter++ } (a) (b) (c) After the processes have executed for some time, it is found that out = 9 and in = 6. How many items are in the buffer? Make a sketch to show the position of the items in the buffer. Justify your answer. When in = out = 5, the buffer is found to be empty. Describe a sequence of events which resulted in this configuration. With reference to the code, explain what happens when in = out = 5, the buffer is empty and it's the consumer's turn to execute.
Expert Answer:
Answer rating: 100% (QA)
Answer A Out5 In 9 this means that in the empty buffer if both the codes did execute without us... View the full answer
Related Book For
Financial Reporting Financial Statement Analysis and Valuation a strategic perspective
ISBN: 978-1337614689
9th edition
Authors: James M. Wahlen, Stephen P. Baginski, Mark Bradshaw
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Assignment 5: Hash Table implementation andconcordance There are three parts to this assignment. In the first two parts,you will complete the implementation of a hash map and aconcordance program. In...
-
On September 30, 2021, Antagonia Real Estate Limited's general ledger showed the following balances: Accounts payable Accounts receivable Advertising expenses Cash Common shares Income tax expense...
-
Using the betatron condition, find the radius of a round orbit of an electron if the magnetic induction is known as a function of distance r from the axis of the field. Examine this problem for the...
-
Refer to the data for Lu Corp. in BE13-17. Prepare any necessary adjusting entries that are associated with the asset retirement obligation and the asset retirement costs at December 31, 2011,...
-
Consider the following cash flow profile and assume MARR is 10 percent/year. a. What does Descartes' rule of signs tell us about the IRR(s) of this project? b. What does Norstrom's criterion tell us...
-
1. Identify the ethical issues involved in the case from a consequentialist and deontological perspective (refer to Chapter 2). 2. Identify the management issues involved in the case. For example,...
-
2. Consider the variation of hot-potato routing/coordination routing game discussed in class, where there are three strategies: Payoff Hot Potato Long Path Planned Long-Path | Planned Hot Potato...
-
Write pseudocode for each example (a through e) in Exercise 2, making sure your pseudocode is structured and accomplishes the same tasks as the flowchart segment. Data From Exercise 2 a. b. D Yes NO...
-
Which transaction will decrease Net Income? write a brief note on this.
-
In the language L((a+b)(a+b+0 + 1 )*) abb01 is a valid string. True False
-
In a grammar G = (V.T. P. S), in production A a, a is in (VUT). True False
-
In which Consensus Algorithm,the coins are 'burned'? a . . PoS b . . PoW c . . PoB d . . PoC
-
Which one of the following is true for form data in Node.js ? ? 1 1 point REQ.BODY contains data submitted using the GET method. REQ.QUERY contains data submitted using POST. You need to require...
-
(7) Knuth class of a tableau T is defined by KT determine the size of KT and also determine KT. = {w such that P(w) = T}. For T = 1345 26
-
15. Webley Corp. issued a $1,000 bond at a coupon rate of 12% paid semiannually, The bond has 30 years remaining, until maturity. Comparable bonds are yielding 8%. What should Webley's bond sell for...
-
When the Department of Homeland Security created a color-coded system to prepare government officials and the public against terrorist attacks, what did it do right and what did it do wrong?
-
Refer to the financial statement data for Abercrombie & Fitch in Problem 4.25 in Chapter 4. Exhibit 5.15 presents risk ratios for Abercrombie & Fitch for fiscal Year 3 and Year 4. Data from 4.25...
-
Sunbeam Corporation manufactures and sells a variety of small household appliances, including toasters, food processors, and waffle grills. Exhibit 3.26 presents a statement of cash flows for Sunbeam...
-
Exhibits 7.17 and 7.18 provide footnote excerpts to the financial reports of The Coca-Cola Company and Eli Lilly and Company that discuss the stock option grants given to the employees of the two...
-
For the pediatrician presented in Example 1, find the probability that a randomly selected three-year-old girl is between 35 and 40 inches tall, inclusive. That is, find P(35 X 40). By-Hand...
-
Find the value of z 0.10 . Approach We wish to find the z-value such that the area under the standard normal curve to the right of the z-value is 0.10.
-
The heights of a pediatricians three-year-old females are approximately normally distributed, with mean 38.72 inches and standard deviation 3.17 inches. Find the height of a three-year-old female at...
Study smarter with the SolutionInn App