Gate2020 cs Q44

0. Each of a set of Q.28 n processes executes the following code using two semaphores a and b initialized to 1 and 0, respectively. Assume that count is a shared variable initialized to 0 and not used in CODE SECTION P.
   CODE SECTION P
wait(a); count=count+1;
if (count==n) signal(b);
signal(a); wait(b); signal(b);
   CODE SECTION Q

What does the code achieve?

  • Option : C
  • Explanation :
    Subject Operating Systems
    a = 1 b = 0 count = 0
    Code section P: For process 1
    Wait (a) ⇒ a = 0
    Count ++ ⇒ count = 1
    If (count = = n) ⇒ false
    signal (a) ⇒ a = 0
    wait (b) process blocked
    As shown above, all processes execute wait (b) before, signal (b) in if condition.
    Because, ‘if’ condition becomes True only for process Pn(nth process) [∵ if (count = = n)]
    So, before Pn process finishes the code section, P, no other process executes code section Q.
    Hence, no process executes code section Q before every process has finished code section P.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *