Home » Operating Systems » Operating systems miscellaneous » Question

Operating systems miscellaneous

  1. Two processes X and Y need to access a critical section. Consider the following synchronization construct used by both the processes
    Process X
    /* other code for process X */
    while (true)
    {
      varP = true;
      while (varQ == true)
      {
    /* critical section */
    varP = false;
      }
    }
    /* other code for process X */
    Process Y
    /* other code for process Y */ while (true)
    {
      varQ = true;
     while (varP == true)
       {
      /* critical section */
    varQ = false;
       }
    }
    /* other code for process Y */
    Here, varP and varQ are shared variables and both are initialized to false. Which one of the following statements is true?
    1. The proposed solution prevents deadlock but fails to guarantee mutual exclusion
    2. The proposed solution guarantees mutual exclusion but fails to prevent deadlock
    3. The proposed solution guarantees mutual exclusion and prevents deadlock
    4. The proposed solution fails to prevent deadlock and fails to guarantee mutual exclusion
Correct Option: A

varP = varQ = FALSE Initially.
Assume that, process X is willing to enter into critical section. So it makes varP = True, then if processor switches to process Y, then process Y can enter into critical section.
After entering into the critical section, then if processor switches to process X, then process X also can enter into the critical section. It is clearly showing that both are in critical section at a time which leads to “failing to guarantee material exclusion”
To enter into the critical section process X is not waiting for process Y and vice versa. So we can “Prevent Deadlock” so, overall, option (a) is correct.



Your comments will be displayed only after manual approval.