Question: Problem D. Consider how to implement a mutex lock using the atomic compare_and_swap() instruction (assuming hardware atomic acquire and release instructions do NOT exist). The
Problem D. Consider how to implement a mutex lock using the atomic compare_and_swap() instruction (assuming hardware atomic acquire and release instructions do NOT exist). The following structure defines the mutex lock, where the value (available == 0) indicates that the mutex lock is available, and a value of 1 (available == 1) indicates that the mutex lock is unavailable.
typedef struct { int available; } mutex_lock;
a. Write C statement(s) to declare a shared variable named me_lock using the above structure, and initialize its value (available)
b. Write C code to re-define void acquire(mutex_lock *mlock) by calling the atomic compare_and_swap() in Slide 3.18 to implement the logic in Slide 3.22 for acquire (warning: no hardware support for atomic acquire in this system)
c. Write C code to re-define void release(mutex_lock *mlock) by calling the atomic compare_and_swap() in Slide 3.18 to implement the logic in Slide 3.22 for release (warning: no hardware support for atomic release in this system)
d. Does this solution require busy waiting such that this mutex lock is still a spinning lock?

compare and swap Instruction Definition: int compare_and swap (int *value, int expected, int new_value) ( int temp - *value; if (*value expected) *value new_value; return temp; 1. Executed atomically 2. Returns the original value of passed parameter "value" 3. Set the variable "value" the value of the passed parameter "new_value" but only if "value"expected". That is, the swap takes place only under this condition. Operating System Concepts-10th Edition 3.18 Silberschatz, Galvin and Gagne 2018 compare and swap Instruction Definition: int compare_and swap (int *value, int expected, int new_value) ( int temp - *value; if (*value expected) *value new_value; return temp; 1. Executed atomically 2. Returns the original value of passed parameter "value" 3. Set the variable "value" the value of the passed parameter "new_value" but only if "value"expected". That is, the swap takes place only under this condition. Operating System Concepts-10th Edition 3.18 Silberschatz, Galvin and Gagne 2018
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
