Question: 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  

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

1 Expert Approved Answer
Step: 1 Unlock

The correct option is iii Is dangerous because if any one ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!