Question: Please explain how you arrived at your answer. In lecture we showed a design for implementing mutex locks that allowed other threads to be scheduled

Please explain how you arrived at your answer. In lecture we showeda design for implementing mutex locks that allowed other threads to bePlease explain how you arrived at your answer.

In lecture we showed a design for implementing mutex locks that allowed other threads to be scheduled when waiting that used spinlocks as part of their implementation: struct Mutex { SpinLock guard_spinlock; bool lock_taken; WaitQueue wait_queue; } LockMutex (Mutex *m) { LockSpinlock(&m->guard_spinlock); if (m->lock_taken) { put current thread on m->wait_queue mark current thread not runnable /* xv6: myproc()->state = SLEEPING; */ UnlockSpinlock(&m->guard_spinlock); run scheduler } else { m->lock_taken = true; UnlockSpinlock(&m->guard_spinlock); } } UnlockMutex (Mutex *m) { LockSpinlock(&m->guard_spinlock); if (m->wait_queue not empty) { remove a thread from m->wait_queue5 make that thread runnable } else { m->lock_taken = false; } UnlockSpinlock(&m->guard_spinlock); } Suppose we wanted to modify this lock design to support a "TryLock" operation that either acquires the lock without the current thread waiting (by running the scheduler or entering an infinte loop) or, if acquring the lock immediately isn't possible, returns an error. Which of the following would correct implementations of this TryLock operation? (Some of these might perform unnecessary extra work, but nevertheless be correct Select all that apply. A. acquire the spinlock; check the lock_taken flag; if it's true, release the spinlock and return an error; otherwise, set lock_taken to true, release the spinlock and return B. check the lock_taken flag, if it's false, call the normal LockMutex function, otherwise return an error acquire the spinlock; check the lock_taken flag and the number of threads on the wait_queue, if the lock_taken flag is false and the number of threads on the wait_queue is 0, then set the lock_taken flag to true, release C. O the spinlock and return. Otherwise, release the spinlock and return an error acquire the spinlock; check the lock_taken flag and the number of threads on the wait_queue; if the lock_taken flag is false or the number of threads on the wait_queue is 0, then set the lock_taken flag to true, release D. the spinlock and return. Otherwise, release the spinlock and return an error In lecture we showed a design for implementing mutex locks that allowed other threads to be scheduled when waiting that used spinlocks as part of their implementation: struct Mutex { SpinLock guard_spinlock; bool lock_taken; WaitQueue wait_queue; } LockMutex (Mutex *m) { LockSpinlock(&m->guard_spinlock); if (m->lock_taken) { put current thread on m->wait_queue mark current thread not runnable /* xv6: myproc()->state = SLEEPING; */ UnlockSpinlock(&m->guard_spinlock); run scheduler } else { m->lock_taken = true; UnlockSpinlock(&m->guard_spinlock); } } UnlockMutex (Mutex *m) { LockSpinlock(&m->guard_spinlock); if (m->wait_queue not empty) { remove a thread from m->wait_queue5 make that thread runnable } else { m->lock_taken = false; } UnlockSpinlock(&m->guard_spinlock); } Suppose we wanted to modify this lock design to support a "TryLock" operation that either acquires the lock without the current thread waiting (by running the scheduler or entering an infinte loop) or, if acquring the lock immediately isn't possible, returns an error. Which of the following would correct implementations of this TryLock operation? (Some of these might perform unnecessary extra work, but nevertheless be correct Select all that apply. A. acquire the spinlock; check the lock_taken flag; if it's true, release the spinlock and return an error; otherwise, set lock_taken to true, release the spinlock and return B. check the lock_taken flag, if it's false, call the normal LockMutex function, otherwise return an error acquire the spinlock; check the lock_taken flag and the number of threads on the wait_queue, if the lock_taken flag is false and the number of threads on the wait_queue is 0, then set the lock_taken flag to true, release C. O the spinlock and return. Otherwise, release the spinlock and return an error acquire the spinlock; check the lock_taken flag and the number of threads on the wait_queue; if the lock_taken flag is false or the number of threads on the wait_queue is 0, then set the lock_taken flag to true, release D. the spinlock and return. Otherwise, release the spinlock and return an error

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!