Question: Implement a spinlock using xchg (exchange primitive) 4. (10 points) Your machine provides atomic exchange (xchg) instruction as its multiprocessor atomic primitive. The semantic and

Implement a spinlock using xchg (exchange primitive) 4. (10 points) Your machineImplement a spinlock using xchg (exchange primitive)

4. (10 points) Your machine provides atomic exchange (xchg) instruction as its multiprocessor atomic primitive. The semantic and definition of the xchg instruction is shown below /* atomic exchange instruction. rl, r2 are registers. atomically swap value in register r2 with memory referenced by rl */ xchg r2, [r1]; swap [r1] with r2 A C 'wrapper function 'exchange()', provided by runtime library, allows programmer to use this primitive int exchange(int value, int *ptr) asm( xchg value, [ptr); return value; Your task is to implement a spinlock using this exchange() primitive class SpinLock private: int value 0; /1 e FREE; 1 BUSY public: void acquire) // implement this using exchange() void release) // implement this 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!