1,417 views
1 1 vote
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;

}

Release Lock(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.

 

The answer given is B, but I feel A should also be the answer as L clearly overflows, as could anyone give a proper explanation as to why option B is correct??

1 Answer

Position:
Show:

Related questions

0 0 votes
0 0 answers
1.9k
1.9k views
garvit_vijai asked Sep 20, 2018
1,855 views
In case of TSL we are aware of the following instructions: 1. TSL LOCK, Ro 2. CMP Ro, #0 3. JNZ step1 Now, the initial value of LOCK is 0 If process Po...
3 3 votes
2 answers 2 answers
3.1k
3.1k views
Nils asked May 25, 2016
3,089 views
Which of the following is true/false Explain it.1) TSL solution method is deadlock free.2)TSL solution method is starvation free.3)TSL solution method process enter into...
0 0 votes
3 3 answers
3.1k
3.1k views
ajit asked Sep 12, 2015
3,112 views
In process synchronization what is true about disabling interrupts and TSL?1)Disabling interrupt is applicable only for single processor system2)TSL is applicable only fo...
0 0 votes
1 1 answer
2.1k
2.1k views
Akriti sood asked Dec 4, 2016
2,073 views
how is deadlock and starvation possible in test and set lock solution of M.E??