Answer to Question #176935 in Algorithms for Tisha

Question #176935


On the MIPS architecture, for example, the load-linked and store-conditional instructions can be

used in tandem to build locks and other concurrent structures. The C pseudocode for these

instructions is shown below. Alpha, PowerPC, and ARM provide similar instructions.

// Actions of thread Ti

1: int LoadLinked(int *ptr) {

2: return *ptr;

3: }

4: int StoreConditional(int *ptr, int value) {

5: if (no other thread has updated *ptr since the last LoadLinked access to *ptr by thread Ti)

6: {

7: *ptr = value;

8: return 1; // success

9: }

10: else {

11: return 0; // failed to update

12: }

13: }

The key difference comes with the store-conditional, which only

succeeds (and updates the value stored at the address just load-linked from) if no intervening store

by another thread to the address has taken place. In the case of success, the store-conditional returns

1 and updates the value at ptr to value; if it fails, the value at ptr is not updated and 0 is returned.

Please develop a mutex lock using this instruction.


1
Expert's answer
2021-04-03T04:16:52-0400
Dear Tisha, your question requires a lot of work, which neither of our experts is ready to perform for free. We advise you to convert it to a fully qualified order and we will try to help you. Please click the link below to proceed: Submit order

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS