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?
acquire) and release acquire ) while (!available) /*busy wait */ available = false;; release available = true; do /* the use of mutex lock in a process*/ acquire lock critical section release lock remainder sectlon l while (true); Operating System Concepts 10th Edition 3.22 Silberschatz, Galvin and Gagne 2018Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started