2. (14 points) The following pseudocode swaps two values in a data structure if both entries...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
2. (14 points) The following pseudocode swaps two values in a data structure if both entries (holding the values) are not null. If either entry is NULL, the data structure is left as before the swap was attempted. The routine must appear to occur atomically and must be highly concurrent - it must allow multiple swaps between unrelated entries in parallel. You may assume that index1 and index2 never refer to the same entry. SwapNonNull(index1, data[index1]->lock. datal = getData(index1); data[index2] ->lock. Acquire(); data2 getData(index2); if (data1 == NULL || data2 else { temp data1->val data2->val temp; } index2) { Acquire(); = return; data1->val; /* May involve disk I/0 */ /* May involve disk I/0 */ NULL) return; == data2->val; storeData (data1); /* Involves disk I/0 */ storeData (data2); /* Involves disk I/0 */ Release(); data[index1]->lock. data[index2]->lock. Release (); State whether the aforementioned routine either (1) works, (ii) doesn't work, or (iii) is dangerous - that is, sometimes works and sometimes doesn't. If the implementation does not work or is dangerous, explain why (there may be several errors) and show how to fix it so it does work. 2. (14 points) The following pseudocode swaps two values in a data structure if both entries (holding the values) are not null. If either entry is NULL, the data structure is left as before the swap was attempted. The routine must appear to occur atomically and must be highly concurrent - it must allow multiple swaps between unrelated entries in parallel. You may assume that index1 and index2 never refer to the same entry. SwapNonNull(index1, data[index1]->lock. datal = getData(index1); data[index2] ->lock. Acquire(); data2 getData(index2); if (data1 == NULL || data2 else { temp data1->val data2->val temp; } index2) { Acquire(); = return; data1->val; /* May involve disk I/0 */ /* May involve disk I/0 */ NULL) return; == data2->val; storeData (data1); /* Involves disk I/0 */ storeData (data2); /* Involves disk I/0 */ Release(); data[index1]->lock. data[index2]->lock. Release (); State whether the aforementioned routine either (1) works, (ii) doesn't work, or (iii) is dangerous - that is, sometimes works and sometimes doesn't. If the implementation does not work or is dangerous, explain why (there may be several errors) and show how to fix it so it does work.
Expert Answer:
Answer rating: 100% (QA)
The correct option is iii Is dangerous because if any one ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
"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...
-
Portray in words what transforms you would have to make to your execution to some degree (a) to accomplish this and remark on the benefits and detriments of this thought.You are approached to compose...
-
In which section do you create VLAN on Cisco WLC ? ? Layer 3 3 Section Layer 2 2 Section Security Section RF Section
-
At January 1, 2015, Bohemia Nursery Ltd.'s balance sheet reported the following shareholders' equity: Shareholders' Equity Contributed capital: Preferred shares, $0.75, cumulative (3 years in...
-
Olivia has received a $15 gift certificate that is redeemable only for roasted peanuts. Bags of roasted peanuts come in two sizes, regular and jumbo. A regular bag contains 30 peanuts and a jumbo bag...
-
Briefly explain how the following programs would affect the elasticity of demand for labor in the steel industry: a. An increased tariff on steel imports. b. A law making it illegal to lay off...
-
A job order cost sheet for Lowry Company is shown below. Instructions (a) On the basis of the foregoing data, answer the following questions. (1) What was the balance in Work in Process Inventory on...
-
The storied American aerospace company, McDonnell Douglas, designed a wide-bodied airliner in the mid-1980s called the MD-11. Research and development costs, plus other fixed costs related to simply...
-
Martha died this year with a net allowable capital loss for the year of death of $100,000. She had income from all sources of $5,000 in the year of death, $30,000 last year, and $27,000 two years...
-
Suppose a friend of yours approaches you and offers to give you $110 in a years period if you agree to give him $100 now. Assume that you are absolutely certain that you will be repaid. What is your...
-
i have 25 pounds of sliver alloy that cointain 8 ounces of pure silver per pound and 16 pounds that have 9.5 ounces of sliver per pound. How much copper must be added to the total so that I can make...
-
1. (35 points) Construct a bus map with the bus stops (letters A through H) in the map below. Each row and column is a two-way street. Your map must have at least 3 bus routes, buses should enter the...
-
What kind of concepts, theories, and/or stories assisted you to further your learning because of your education? Can you recall your memory lapses (stories you did not hear) that are now apparent?
-
There are 12 face cards in a deck of standard playing cardsand 20 even numbered cards. If you draw one card and look at it.Then replace it and then draw another card. What is the probabilitythat you...
-
14. The diameter of a quarter is 24.26 millimeters. Is it more appropriate to post the diameter as 24.26 millimeters or 2.426 X 10-5 kilometers? Explain your reasoning.
-
What would you select from the main menu if an employee breaks a piece of inventory? Vendors and Payables??Inventory Adjustments Vendors and Payables>>Damaged Inventory Inventory and...
-
Determine the optimal use of Applichem's plant capacity using the Solver in Excel.
-
The health department of a large city has developed an air pollution index that measures the level of several air pollutants that cause respiratory distress in humans. The accompanying table gives...
-
A random sample of 25 students taken from a university gave the variance of their GPAs equal to .19. a. Construct the 99% confidence intervals for the population variance and standard deviation....
-
For a population, N = 30,000 and p = .59. Find the z value for each of the following for n = 100. a. p = .56 b. p = .68 c. p = .53 d. p = .65
-
Supposing that all systems in Figure 1.27 are linear and time invariant, compute \(y(n)\) as a function of the input and the impulse responses of each system. x(n) h(n) h(n) h(n) Fig. 1.27. Linear...
-
Find one solution for each of the difference equations below: (a) \(y(n)+2 y(n-1)+y(n-2)=0, y(0)=1\) and \(y(1)=0\) (b) \(y(n)+y(n-1)+2 y(n-2)=0, y(-1)=1\) and \(y(0)=1\).
-
We define the even and odd parts of a sequence \(x(n), \mathcal{E}\{x(n)\}\) and \(\mathcal{O}\{x(n)\}\) respectively, as \[\begin{aligned}\mathcal{E}\{x(n)\} & =\frac{x(n)+x(-n)}{2}...
Study smarter with the SolutionInn App