Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. (14 points) The following pseudocode swaps two values in a data structure if both entries (holding the values) are not null. If either

   

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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

The correct option is iii Is dangerous because if any one ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introductory Statistics

Authors: Prem S. Mann

8th Edition

9781118473986, 470904100, 1118473981, 978-0470904107

More Books

Students also viewed these Programming questions

Question

Discuss brief psychodynamic psychotherapy approaches.

Answered: 1 week ago

Question

Solve the following proportions for the unknown quantities

Answered: 1 week ago