Question: Implement multiprocessor spinlock using this instruction. write code in C or C++, clearly identify the values of lock states, and show implementation of acquire() and
Implement multiprocessor spinlock using this instruction.
write code in C or C++, clearly identify the values of lock states, and show implementation of acquire() and release().

compare old and *ptr update ptr with new only if they are the same return most recent *ptr value int compare and swap (int ptr int old, int new asm cas new, old, Uptr return old For example, to atomically add a value to a shared variable in multiprocessor system, you can use compare and swap as follows: void atomic add(int ptr int val int res, old ptr while (1) res compare and swap (ptr old old+val); if (res old) break old res compare old and *ptr update ptr with new only if they are the same return most recent *ptr value int compare and swap (int ptr int old, int new asm cas new, old, Uptr return old For example, to atomically add a value to a shared variable in multiprocessor system, you can use compare and swap as follows: void atomic add(int ptr int val int res, old ptr while (1) res compare and swap (ptr old old+val); if (res old) break old res
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
