68 68 votes The following two functions $P1$ and $P2$ that share a variable $B$ with an initial value of $2$ execute concurrently. $$\begin{array}{|l|l|}\hline \text{P1() \{ } & \text{P2()\{} \\ \text{ C = B - 1;} & \text{ D = 2 * B; } \\ \text{ B = 2 * C;} & \text{ B = D - 1;} \\ \text{\}} & \text{\}} \\\hline \end{array}$$ The number of distinct values that $B$ can possibly take after the execution is______________________. Operating System gatecse-2015-set1 operating-system process-synchronization normal numerical-answers + – Misbah Ghaya 24.0k views answer comment Share Follow Print See all 5 Comments 5 5 Comments reply Show 2 previous comments ankit2024 commented Nov 22, 2025 reply Follow flag read question care fully it is asked for distict value of B not whole program distinct value this cane be the silly mistake i made this miskake during testtoatl 4 distinct value that is 1,2,3,4and B having 3 distinct value that is 4,3,2 4 4 replyShare chidambareswar23 commented Dec 25, 2025 reply Follow flag Similar question instead of two functions it is given two threads:Operating System: GATE CSE 2024 | Set 1 | Question: 30 0 0 replyShare Strawhat Luffy commented Sep 12 reply Follow flag It's so Simple with cases :Case 1 : P1 then P2 (executes serially). In this order B will be 3.Case 2 : P2 then P1 (serially). In this order B will be 4.Case 3 : when both P1, P2 read the same value B=2, but write one after the other. 1) P1 writes first then P2. In this case P1's B value(B=2) will be overwrite by P2(B=3). So at last B will be 3. 2) P2 writes first then P2. In this case P2's B value(B=3) will be overwrite by P1(B=2). So at last B will be 2.hence B can be 2,3, or 4.So 3 unique values of B possible. 0 0 replyShare Please log in or register to add a comment.
0 0 votes The 4 Quick Math TracksTrack 1 ($P_1 \rightarrow P_2$ Completely):$P_1$ finishes: $C = 2 - 1 = 1 \rightarrow B = 2 \times 1 = 2$.$P_2$ takes over with $B = 2$: $D = 2 \times 2 = 4 \rightarrow \mathbf{B = 3}$.Track 2 ($P_2 \rightarrow P_1$ Completely):$P_2$ finishes: $D = 2 \times 2 = 4 \rightarrow B = 4 - 1 = 3$.$P_1$ takes over with $B = 3$: $C = 3 - 1 = 2 \rightarrow \mathbf{B = 4}$.Track 3 ($P_1$ Starts $\rightarrow P_2$ Finishes $\rightarrow P_1$ Overwrites):$P_1$ copies $B=2$ to compute $C=1$ and pauses.$P_2$ runs completely and changes $B$ to $3$.$P_1$ wakes up, ignores the change, and applies its cached $C=1$: $B = 2 \times 1 = \mathbf{2}$.Track 4 ($P_2$ Starts $\rightarrow P_1$ Finishes $\rightarrow P_2$ Overwrites):$P_2$ copies $B=2$ to compute $D=4$ and pauses.$P_1$ runs completely and keeps $B$ at $2$.$P_2$ wakes up and applies its cached $D=4$: $B = 4 - 1 = \mathbf{3}$.Unique Set: The final values can only be --- {2, 3, 4}. VIPIN_CHANDRA answered May 16 VIPIN_CHANDRA comment Share Follow 0 reply Please log in or register to add a comment.