Skip to main content

GATE CSE 2009Operating System › Process Synchronization & ConcurrencyVerified

GATE CSE 2009 PYQ: The enter_CS() and leave_CS() functions to implement critical section of a process are realized using…

The enter_CS() and leave_CS() functions to implement critical section of a process are realized using test-and-set instruction as follows:

void enter_CS(X)
{
    while(test-and-set(X));
}

void leave_CS(X)
{
    X = 0;
}

In the above solution, XX is a memory location associated with the CSCS and is initialized to 0. Now consider the following statements:

  1. The above solution to CSCS problem is deadlock-free

  2. The solution is starvation free

  3. The processes enter CSCS in FIFO order

  4. More than one process can enter CSCS at the same time

Which of the above statements are TRUE?

  1. A
    (I) only
    Correct answer
  2. B
    (I) and (II)
  3. C
    (II) and (III)
  4. D
    (IV) only

Answer

(A) (I) only

Approach

Treat X as a binary lock implemented by the atomic test-and-set instruction. Evaluate each of the four statements: deadlock-freedom, starvation-freedom, FIFO ordering, and mutual exclusion.

The implementation acts as a test-and-set spinlock. It guarantees mutual exclusion and is deadlock-free, but it does not guarantee bounded waiting/starvation-freedom, FIFO ordering, or concurrent CS entry. Therefore only statement I is true, so option A is correct.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.