Question: CPU often provides atomic instructions for lock implementations. For example, x86s xchg instruction atomically exchanges the contents of two memory addresses. Implement a spin lock

CPU often provides atomic instructions for lock implementations. For example, x86s xchg instruction atomically exchanges the contents of two memory addresses. Implement a spin lock with this instruction, assuming xchg has been provided as a library function

// xchg sets the memory (addr) to newval, and returns the old value.

extern int xchg (int *addr, int newval);

struct spinlock { unsigned int locked;

};

{

}

void spinlock_release (struct spinlock *lock)

{

void spinlock_acquire (struct spinlock *lock)

}

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!