Question: Consider the following function that implements acquiring a lock ( assume that TestAndSet is an atomic instruction ) . Observe that this code's approach to

Consider the following function that implements acquiring a lock (assume that TestAndSet is an atomic instruction). Observe that this code's approach to waiting for a held lock to be released is to "spin". void lock (lock_ t *lock)1while (TestAndSet (&lock->flag, 1)==1); // spin-wait (do nothing)i) Briefly explain why the way this code spins is inefficient and wastes resources.ii) Briefly explain how this code could be modified to avoid that inefficiency. (Hint: we studied two different strategies; either is an acceptable answer here)

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!