Consider how to implement a mutex lock using an atomic hardware instruction. Assume that the following structure defining the mutex
lock is available:
typedef struct {
int available;
} lock;
(available == 0) indicates that the lock is available, and a value of 1 indicates that the lock is unavailable. Using this struct, illustrate how the following functions can be implemented using the test and set() and compare and swap() instructions:
• $void acquire(lock *mutex)$
•$ void release(lock *mutex)$
Be sure to include any initialization that may be necessary.