Question

Consider the following transactions with data items PP and QQ initialized to zero:

T1T_1:
read (PP);
read (QQ);
if P=0P = 0 then Q:=Q+1Q := Q + 1;
write (QQ).

T2T_2:
read (QQ);
read (PP);
if Q=0Q = 0 then P:=P+1P := P + 1;
write (PP).

Any non-serial interleaving of T1T_1 and T2T_2 for concurrent execution leads to

Choose one option
Official answer and solution
Official answer
B
From
Official GATE 2012 answer key

Solution

Trace conflicting read/write operations on data items P and Q across all possible non-serial interleavings of transactions T1 and T2.

  1. Operations in each transaction:
  • T1T_1: reads PP, reads QQ, writes QQ (if P=0P = 0).
  • T2T_2: reads QQ, reads PP, writes PP (if Q=0Q = 0).
  1. Conflicting pairs between T1T_1 and T2T_2:
  • Conflict on item QQ: R2(Q)R_2(Q) and W1(Q)W_1(Q) are in conflict.
  • Conflict on item PP: R1(P)R_1(P) and W2(P)W_2(P) are in conflict.
  1. In any non-serial interleaving of T1T_1 and T2T_2:
  • Because T1T_1 begins by reading PP before T2T_2 writes PP, the conflict R1(P)<W2(P)R_1(P) < W_2(P) introduces a directed edge T1→T2T_1 \to T_2 in the serialization (precedence) graph.
  • Concurrently, because T2T_2 reads QQ before T1T_1 writes QQ, the conflict R2(Q)<W1(Q)R_2(Q) < W_1(Q) introduces a reverse directed edge T2→T1T_2 \to T_1 in the precedence graph.
  1. Thus, both directed edges T1→T2T_1 \to T_2 and T2→T1T_2 \to T_1 are present, forming a directed cycle in the precedence graph.

  2. A schedule is conflict serializable if and only if its precedence graph contains no directed cycles. Since a cycle is unavoidably created in every non-serial interleaving, any non-serial execution leads to a schedule that is not conflict serializable.

Final answer

B

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2012 Computer Science and Information Technology (CS)
Question
27 of 65, printed as CS Q.27
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.