CompleteGATE Doubts Forum
0 like 0 dislike
212 views

Fetch_And_Add(X,i) is an atomic Read-Modify-Write instruction that reads the value of memory location X, increments it by the value i, and returns the old value of X. It is used in the pseudocode shown below to implement a busy-wait lock. L is an unsigned integer shared variable initialized to 0. The value of 0 corresponds to lock being available, while any non-zero value corresponds to the lock being not available. 

         AcquireLock(L) { 

               while (Fetch_And_Add(L,1))

                     L = 1; 

         } 

         ReleaseLock(L) { 

               L = 0; 

         }

This implementation

(A) fails as L can overflow

(B) fails as L can take on a non-zero value when the lock is actually available

(C) works correctly but may starve some processes

(D) works correctly without starvation 

asked Jul 2, 2016 in Operating Systems by CompleteGATE-AskUS (3,550 points)
edited Jul 2, 2016 by CompleteGATE-AskUS | 212 views

1 Answer

1 like 0 dislike
Best answer

(B) fails as L can take on a non-zero value when the lock is actually available

answered Jul 2, 2016 by ebeisaac (13,250 points)
selected Jul 11, 2016 by CompleteGATE-AskUS
Welcome to Completegate AskUs, A place where you can ask questions regarding videos located at Youtube Channel and receive answers from our experts.

Sign up for our newsletter to receive the latest news and event postings.

Best Users 10/2019
  1. CompleteGATE-AskUS

    3550 Points

  2. Asma Abbasi

    200 Points

  3. Henry

    150 Points

  4. SilverChat

    140 Points

Rewards per month
First Winner: 0 INR (Not Started)
Second Winner: 0 INR (Not Started)

×

Like us on Facebook

Show your Support. Become a FAN!

107 questions
100 answers
2 comments
76 users