Synchronization
GATE CSE & IT · 31 questions across 22 years (1990-2026) · 55% recurrence rate
Recurrence sparkline
1990–2026Difficulty mix
Question types
All 31 questions on Synchronization
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...
Consider the following two threads T1 and T2 that update two shared variables a and b. Assume that initially $a = 1$ and $b = 1$. Though context switching between threads can happen at any time, each statement of T1 or T...
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...
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...
Consider the following threads, T 1 , T 2 and T 3 executing on a single processor, synchronized using three binary semaphore variables, S 1 , S 2 and S 3 , operated upon using standard wait( ) and signal( ). The threads...
Consider the following pseudocode, where S is a semaphore intialized to 5 in line#2 an counter is a shared variable intialized to 0 in line#1. Assume that the increment operation in line#7 is not atomic. 1. int counter =...
Consider a non-negative counting semaphore $$S.$$ The operation $$P(S)$$ decrements $$S,$$ and $$V(S)$$ increments $$S.$$ During an execution, $$20$$ $$P(S)$$ operations and $$12$$ $$V(S)$$ operations are issued in some...
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 poss...
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); }...
A certain computation generates two arrays a and b such that a[i]=f(i)for 0 ≤ i < n and b[i] = g (a[i] )for 0 ≤ i < n. Suppose this computation is decomposed into two concurrent processes X and Y such that X computes the...
A shared variable x, initialized to zero, is operated on by four concurrent processes W, X, Y, Z as follows. Each of the processes W and X reads x from memory, increments by one, stores it to memory, and then terminates....
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 impleme...
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 abo...
The P and V operations on counting semaphores, where s is a counting semaphore, are defined as follows: P(s): s = s-1; if s < 0 then wait; V(s) : s = s-1; ifs <= 0 then wakeup a process waiting on s; Assume that P b and...
Two processes, P1 and P2, need to access a critical section of code. Consider the following synchronization construct used by the processes: /* P1 */ while(true){ want s1=true; while(wants2 == true){ /* Critical Section...
Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let t...
The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x n y without allowing any intervening access to the memory location x. consider the following implem...
Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let t...
Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below. Process P: while(1){ W: Print '0'; Print '0'; X: } Process Q: while(1){...
Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below. Process P: while(1){ W: Print '0'; Print '0'; X: } Process Q: while(1){...
Consider Peterson’s algorithm for mutual exclusion between two concurrent processes i and j. The program executed by process is shown below. Repeat flag[i]=true; turn=j; while (P) do no-op; Enter critical section, perfor...
When the result of a computation depends on the speed of the processes involved there is said to be
A counting semaphore was initialized to 10. Then 6 P (wait) operations and 4 V (signal) operations were completed on this semaphore. The resulting value of the semaphore
Each process P i ,i=1.....9 is coded as follows Repeat P(mutex){ critical section } V(mutex) Forever The code for P 10 is identical except that it uses V(mutex) in place of P(mutex). What is the largest number of process...
A critical section is a program segment
A solution to the Dining Philosophers Problem which avoids deadlock is
At a particular time of computation the value of a counting semaphore is 7. Then 20 P operations and 15 V operations were completed on this semaphore. The resulting value of the semaphore is:
State whether the following statement TRUE or FALSE. Any implementation of a critical section requires the use of an indivisible machine instruction such as test-and-set.
State whether the following statement TRUE or FALSE. The use of monitors ensures that no dead -locks will be caused.
Semaphore operations are atomic because they are implemented within the OS
Match the pairs in the following Question. $$\eqalign{ & \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,List:\,{\rm I} \cr & \left( A \right)\,\,Criotical\,\,region \cr & \left( B \right)\,\,Wait/Signal \cr & \left( C \right)\,\,Working\...