Process Synchronization: GATE CS Previous Year Questions

Process Synchronization · Operating System

41 questions · asked in 23 of 27 years (2000–2026)

MCQ 34 · MSQ 4 · NAT 31-mark 22 · 2-mark 19

2000Questions per year2026

Questions 6–10 of 41

Q6GATE 2021 (Session 1)2 marksMSQ
Consider the following pseudocode, where S is a semaphore initialized to 5 in line #2 and counter is a shared variable initialized to 0 in line #1. Assume that the increment operation in line #7 is not atomic.
1.  int counter =0;
2.  Semaphore S= init(5);
3.  void parop(void)
4.  {
5.         wait(S);
6.         wait(S);
7.         counter++;
8.         signal(S);
9.          signal(S);
10.  } 
If five threads execute the function paropparop concurrently, which of the following program behavior(s) is/are possible?

One or more options are correct.

Q7GATE 2021 (Session 2)2 marksMSQ
Consider a computer system with multiple shared resource types, with one instance per resource type. Each instance can be owned by only one process at a time. Owning and freeing of resources are done by holding a global lock (L). The following scheme is used to own a resource instance:
 function OWNRESOURCE(Resource R) 
    Acquire lock L // a global lock 
    if R is available then 
        Acquire R        
        Release lock L 
    else
        if R is owned by another process P then        
        Terminate P, after releasing all resources owned by P        
        Acquire R        
        Restart P        
        Release lock L        
        end if
    end if    
end function
Which of the following choice(s) about the above scheme is/are correct?

One or more options are correct.

Q8GATE 20202 marksMCQ−0.67 if wrong
Each of a set of 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?

Q9GATE 20191 markNAT
Consider three concurrent processes P1, P2 and P3 as shown below, which access a shared variable D that has been initialized to 100.
P1 D = D + 20 P2 D = D – 50 P3 D = D + 10
The process are executed on a uniprocessor system running a time-shared operating system. If the minimum and maximum possible values of D after the three processes have completed execution are X and Y respectively, then the value of Y-X is __________.

Q10GATE 20182 marksMCQ−0.67 if wrong
Consider the following solution to the producer-consumer synchronization problem. The shared buffer size is N. Three semaphores empty, full and mutex are defined with respective initial values of 0, N and 1. Semaphore empty denotes the number of available slots in the buffer, for the consumer to read from. Semaphore full denotes the number of available slots in the buffer, for the producer to write to. The placeholder variables, denoted by P, Q, R, and S, in the code below can be assigned either empty or full. The valid semaphore operations are: wait() and signal().
Producer:                   Consumer:

do{                         do{
    wait(P);                    wait(R);
    wait(mutex);                wait(mutex);
    //Add item to buffer        //Consume item from buffer
    signal(mutex);              signal(mutex);
    signal(Q);                  signal(S);
}while(1);                  }while(1);

Which one of the following assignments to P, Q, R and S will yield the correct solution?

Keep practising

Topics in Operating System

All CS topics ›