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?

Problem D. Consider how to implement a mutex lock using the atomic

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 2018

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!