Skip to content
Official PYQ · 2012

GATE CS 2012 Q27 — Transactions and Concurrency Control

Explain with AI

Consider the following transactions with data items PP and QQ initialized to zero:
T_1read (P);read (Q);if P = 0 then Q := Q + 1; write (Q)T_2read (Q);read (P);if Q = 0 then P := P + 1;write (P){\begin{array}{|c|l|r|c|}\hline \textbf{$T\_1$}& \text{read (P);}\\ & \text{read (Q);} \\ & \text{if P = 0 then Q := Q + 1; }\\ & \text{write (Q)} \\ \hline \textbf{$T\_2$}& \text{read (Q);}\\& \text{read (P);} \\ & \text{if Q = 0 then P := P + 1;} \\ & \text{write (P)} \\ \hline \end{array}}

Any non-serial interleaving of T1 and T2 for concurrent execution leads to

Choose one option
View worked solution

Answer: B

To determine the conflict serializability of any non-serial interleaving of transactions T1T_1 and T2T_2, we identify their conflicting operations on shared data items PP and QQ:

  • T1T_1: r1(P)→r1(Q)→w1(Q)r_1(P) \to r_1(Q) \to w_1(Q)
  • T2T_2: r2(Q)→r2(P)→w2(P)r_2(Q) \to r_2(P) \to w_2(P)

The conflicting pairs of operations are:

  1. r1(P)r_1(P) and w2(P)w_2(P) on data item PP
  2. r2(Q)r_2(Q) and w1(Q)w_1(Q) on data item QQ

For any schedule to be non-serial:

  • T1T_1 cannot completely finish before T2T_2 starts. Thus, the first operation of T2T_2, which is r2(Q)r_2(Q), must execute before the last operation of T1T_1, which is w1(Q)w_1(Q). This write-after-read conflict (r2(Q)→w1(Q)r_2(Q) \to w_1(Q)) creates a precedence edge: T2→T1T_2 \to T_1.
  • Similarly, T2T_2 cannot completely finish before T1T_1 starts. Thus, the first operation of T1T_1, which is r1(P)r_1(P), must execute before the last operation of T2T_2, which is w2(P)w_2(P). This write-after-read conflict (r1(P)→w2(P)r_1(P) \to w_2(P)) creates a precedence edge: T1→T2T_1 \to T_2.

Since any non-serial interleaving forces both edges T1→T2T_1 \to T_2 and T2→T1T_2 \to T_1, the precedence graph will always contain a cycle. Therefore, any non-serial interleaving is not conflict serializable.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Transactions and Concurrency Control questions