Answered step by step
Verified Expert Solution
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 ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started