Concurrency and Synchronization questions

Q51

GATE CS 2026 CS-2Concurrency and SynchronizationMSQ2 marks
Consider three processes P1, P2, and P3 running identical code, as shown in the pseudocode below. A and B are two binary semaphores initialized to 1 and 0, respectively. X is a shared variable initialized to 0. Each line in the pseudocode is executed atomically.

Pseudocode of P1, P2, and P3
 Wait(A);
 Print(*);
 X = X+1;
 If (X == 2)
 {
 Print($);
 Signal(B);
 }
 Signal(A);
 Wait(B);
 Print(#);
 Signal(B);
Assume that any of the three processes can start to execute first and context switching can happen between these processes at any arbitrary time and in any arbitrary order.

Which of the following patterns is/are possible to be generated as an outcome of the execution of these three processes?
More than one option can be correct.
Show answer without attempting

Answer: A, B, C

Q40

GATE CS 2024 CS-1Concurrency and SynchronizationMCQ2 marks−2/3 if wrong
Consider the following two threads T1 and T2 that update two shared variables a and b. Assume that initially a = b = 1. Though context switching between threads can happen at any time, each statement of T1 or T2 is executed atomically without interruption.
T1:
a = a + 1;
b = b + 1;
T2:
b = 2 * b;
a = 2 * a;
Which one of the following options lists all the possible combinations of values of a and b after both T1 and T2 finish execution?
Show answer without attempting

Answer: A

Q46

GATE CS 2024 CS-2Concurrency and SynchronizationMSQ2 marks
Consider a multi-threaded program with two threads T1 and T2. The threads share two semaphores: s1 (initialized to 1) and s2 (initialized to 0). The threads also share a global variable x (initialized to 0). The threads execute the code shown below.
// code of T1
wait(s1);
x = x+1;
print(x);
wait(s2);
signal(s1);

// code of T2
wait(s1);
x = x+1;
print(x);
signal(s2);
signal(s1);
Which of the following outcomes is/are possible when threads T1 and T2 execute concurrently?
More than one option can be correct.
Show answer without attempting

Answer: B, C

Q38

GATE CS 2023 CSConcurrency and SynchronizationMCQ2 marks−2/3 if wrong
Consider the two functions incr and decr shown below.
incr(){
wait(s);
X = X+1;
signal(s);
}
decr(){
wait(s);
X = X-1;
signal(s);
}
There are 5 threads each invoking incr once, and 3 threads each invoking decr once, on the same shared variable X. The initial value of X is 10.
Suppose there are two implementations of the semaphore s, as follows:

I-1: s is a binary semaphore initialized to 1.
I-2: s is a counting semaphore initialized to 2.

Let V1, V2 be the values of X at the end of execution of all the threads with implementations I-1, I-2, respectively.

Which one of the following choices corresponds to the minimum possible values of V1, V2, respectively?
Show answer without attempting

Answer: C

Q19

GATE CS 2022 CSConcurrency and SynchronizationMCQ1 mark−1/3 if wrong
Consider the following threads, T1T_1, T2T_2, and T3T_3 executing on a single processor, synchronized using three binary semaphore variables, S1S_1, S2S_2, and S3S_3, operated upon using standard wait() and signal(). The threads can be context switched in any order and at any time.
T1
while(true){
  wait(S3);
  print(“C”);
  signal(S2);
}

T2
while(true){
  wait(S1);
  print(“B”);
  signal(S3);
}

T3
while(true){
  wait(S2);
  print(“A”);
  signal(S1);
}
Which initialization of the semaphores would print the sequence BCABCABCA....?
Show answer without attempting

Answer: C

Q46

GATE CS 2021 CS-1Concurrency and SynchronizationMSQ2 marks
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 parop concurrently, which of the following program behavior(s) is/are possible?
More than one option can be correct.
Show answer without attempting

Answer: A, B, D

Q34

GATE CS 2020 CSConcurrency and SynchronizationMCQ2 marks−2/3 if wrong
Each of a set of nn 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?
Show answer without attempting

Answer: A

Q23

GATE CS 2019 CSConcurrency and SynchronizationNAT1 mark
Consider three concurrent processes P1, P2 and P3 as shown below, which access a shared variable D that has been initialized to 100.
P1P2P3
⋮\vdots⋮\vdots⋮\vdots
D=D+20\text{D} = \text{D} + 20D=D−50\text{D} = \text{D} - 50D=D+10\text{D} = \text{D} + 10
⋮\vdots⋮\vdots⋮\vdots
The processes 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−XY - X is __________.
Show answer without attempting

Answer: 80

Q40

GATE CS 2018 CSConcurrency and SynchronizationMCQ2 marks−2/3 if wrong
Consider the following solution to the producer-consumer synchronization problem. The shared buffer size is NN. Three semaphores empty, full and mutex are defined with respective initial values of 0,N0, N and 11. 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:
do{
 wait(P);
 wait(mutex);
 //Add item to buffer
 signal(mutex);
 signal(Q);
}while(1);
Consumer:
do{
 wait(R);
 wait(mutex);
 //Consume item from buffer
 signal(mutex);
 signal(S);
}while(1);
Which one of the following assignments to P, Q, R and S will yield the correct solution?
Show answer without attempting

Answer: C

Q27

GATE CS 2017 CS-1Concurrency and SynchronizationMCQ2 marks−2/3 if wrong
A multithreaded program PP executes with xx number of threads and uses yy number of locks for ensuring mutual exclusion while operating on shared memory locations. All locks in the program are non-reentrant, i.e., if a thread holds a lock ll, then it cannot re-acquire lock ll without releasing it. If a thread is unable to acquire a lock, it blocks until the lock becomes available. The minimum value of xx and the minimum value of yy together for which execution of PP can result in a deadlock are:
Show answer without attempting

Answer: D

Q50

GATE CS 2016 CS-1Concurrency and SynchronizationMCQ2 marks−2/3 if wrong
Consider the following proposed solution for the critical section problem. There are n processes: P0…Pn−1P_0 \dots P_{n-1}. In the code, function pmax returns an integer not smaller than any of its arguments. For all i, t[i] is initialized to zero.
Code for PiP_i:
do {
    c[i]=1; t[i] = pmax(t[0],...,t[n-1])+1; c[i]=0;
    for every j ≠ i in {0,...,n-1} {
        while (c[j]);
        while (t[j] != 0 && t[j]<=t[i]);
    }
    Critical Section;
    t[i]=0;
    Remainder Section;
} while (true);
Which one of the following is TRUE about the above solution?
Show answer without attempting

Answer: A

Q48

GATE CS 2016 CS-2Concurrency and SynchronizationMCQ2 marks−2/3 if wrong
Consider the following two-process synchronization solution.
Process 0                         Process 1
---------                         ---------
Entry: loop while (turn == 1);    Entry: loop while (turn == 0);
  (critical section)                (critical section)
Exit:  turn = 1;                  Exit:  turn = 0;
The shared variable turn is initialized to zero. Which one of the following is TRUE?
Show answer without attempting

Answer: C

Q49

GATE CS 2016 CS-2Concurrency and SynchronizationNAT2 marks
Consider a non-negative counting semaphore SS. The operation P(S)P(S) decrements SS, and V(S)V(S) increments SS. During an execution, 20 P(S)20\, P(S) operations and 12 V(S)12\, V(S) operations are issued in some order. The largest initial value of SS for which at least one P(S)P(S) operation will remain blocked is _________.
Show answer without attempting

Answer: 7.0

Q31

GATE CS 2015 CS-3Concurrency and SynchronizationMCQ1 mark−1/3 if wrong
Two processes XX and YY 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?
Show answer without attempting

Answer: A

Q30

GATE CS 2015 CS-1Concurrency and SynchronizationNAT1 mark
The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.
P1() {
    C = B - 1;
    B = 2 * C;
}

P2() {
    D = 2 * B;
    B = D - 1;
}
The number of distinct values that B can possibly take after the execution is ________.
Show answer without attempting

Answer: 3

Q31

GATE CS 2014 CS-2Concurrency and SynchronizationMCQ2 marks−2/3 if wrong
Consider the procedure below for the Producer-Consumer problem which uses semaphores:
semaphore n = 0;
semaphore s = 1;

void producer()
{
    while(true)
    {
        produce();
        semWait(s);
        addToBuffer();
        semSignal(s);
        semSignal(n);
    }
}

void consumer()
{
    while(true)
    {
        semWait(s);
        semWait(n);
        removeFromBuffer();
        semSignal(s);
        consume();
    }
}
Which one of the following is TRUE?
Show answer without attempting

Answer: C

Q34

GATE CS 2013 CSConcurrency and SynchronizationMCQ2 marks−2/3 if wrong
A shared variable xx, initialized to zero, is operated on by four concurrent processes W, X, Y, Z as follows. Each of the processes W and X reads xx from memory, increments by one, stores it to memory, and then terminates. Each of the processes Y and Z reads xx from memory, decrements by two, stores it to memory, and then terminates. Each process before reading xx invokes the PP operation (i.e., wait) on a counting semaphore SS and invokes the VV operation (i.e., signal) on the semaphore SS after storing xx to memory. Semaphore SS is initialized to two. What is the maximum possible value of xx after all processes complete execution?
Show answer without attempting

Answer: D

Q39

GATE CS 2013 CSConcurrency and SynchronizationMCQ2 marks−2/3 if wrong
A certain computation generates two arrays aa and bb such that a[i]=f(i)a[i]=f(i) for 0≤i<n0 \le i < n and b[i]=g(a[i])b[i] = g(a[i]) for 0≤i<n0 \le i < n. Suppose this computation is decomposed into two concurrent processes X and Y such that X computes the array aa and Y computes the array bb. The processes employ two binary semaphores RR and SS, both initialized to zero. The array aa is shared by the two processes. The structures of the processes are shown below.
Process X:
private i;
for (i=0; i<n; i++) {
  a[i] = f(i);
  ExitX(R, S);
}

Process Y:
private i;
for (i=0; i<n; i++) {
  EntryY(R, S);
  b[i] = g(a[i]);
}
Which one of the following represents the CORRECT implementations of ExitX and EntryY?
Show answer without attempting

Answer: C

Q32

GATE CS 2012 CSConcurrency and SynchronizationMCQ2 marks−2/3 if wrong
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
Show answer without attempting

Answer: B

0/190 correct0 marks

Related topics in Operating Systems