Exams › GATE › Technical
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
- fails as L can overflow
- fails as L can take on a non-zero value when the lock is actually available
- works correctly but may starve some processes
- works correctly without starvation
Correct answer: fails as L can take on a non-zero value when the lock is actually available
Solution
The implementation fails because the Fetch_And_Add operation increments L even when it is already non-zero, which means that the lock can appear to be held (non-zero) even when it is actually available (zero). This can lead to situations where a process believes the lock is not available when it is, causing incorrect behavior.
Related GATE Technical questions
- The three-dimensional state of stress at a point is given by σ = [[10, 0, 0],[0, 40, 0],[0, 0, 0]] MPa. The maximum shear stress at the point is
- A 2 m wide strip footing is founded at a depth of 1.5 m below the ground level in a homogeneous pure clay bed. The clay bed has unit cohesion of 40 kPa. Due to seasonal fluctuations of water table from peak summer to peak monsoon period, the net ultimate bearing capacity of the footing, as per Terzaghi’s theory, will
- Consider the statements P and Q.
P: Soil particles formed by mechanical weathering, and close to their origin are generally subrounded.
Q: A activity of the clay physically signifies its swell potential.
Which one of the following options is CORRECT?
- The number of degrees of freedom for a natural open channel flow with a mobile bed is
- The following table gives various components of Municipal Solid Waste (MSW) and a list of treatment/separation techniques.
Component of MSW
P - Ferrous metals
Q - Aluminum and copper
R - Food waste
S - Cardboard
Treatment/separation technique
i - Incineration
ii - Rapid composting
iii - Eddy current separator
iv - Magnetic separator
The CORRECT match is
- A car is travelling at a speed of 60 km/hr on a section of a National Highway having a downward gradient of 2%. The driver of the car suddenly observes a stopped vehicle on the car path at a distance of 130 m ahead, and applies brake. If the brake efficiency is 60%, coefficient of friction is 0.7, driver's reaction time is 2.5 s, and acceleration due to gravity is 9.81 m/s², the distance (in meters) required by the driver to bring the car to a safe stop lies in the range
⚔️ Practice GATE Technical free + battle 1v1 →