Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Fetch_And_Add(X,i) is an atomic Read-Modify-Write instruction that re memory loc

ID: 157271 • Letter: F

Question

Fetch_And_Add(X,i) is an atomic Read-Modify-Write instruction that re
memory location X, increments it by the value i, and returns the old value of X. It
pseudocode shown below to implement a busy-wait lock. L is an unsigned in
initialized to 0. The value of 0 corresponds to lock being available, while any non
corresponds to the lock being not available.   AcquireLock(L){      while (Fetch_And_Add(L,1)     L = 1;   }   ReleaseLock(L){
         L = 0;   }
This implementation :

?
1) fails as L can overflow
2) fails as L can take on a non-zero value when the lock is actually available
3) works correctly but may starve some processes
4) works correctly without starvation

Explanation / Answer

fails as L can overflow