Consider the following transactions with data items P and Q initialized to…

2012

Consider the following transactions with data items P and Q initialized to zero:

T1 :read (P);
     read (Q);
     if P = 0 then Q := Q + 1 ;
     write (Q).
T2 : read (Q);
     read (P);
     if Q = 0 then P := P + 1 ;
     write (P).

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

  1. A.

    a serializable schedule

  2. B.

    a schedule that is not conflict serializable

  3. C.

    a conflict serializable schedule

  4. D.

    a schedule for which a precedence graph cannot be drawn

Attempted by 147 students.

Show answer & explanation

Correct answer: B

Answer: a schedule that is not conflict serializable

Reasoning:

  • Initial values: P = 0, Q = 0.

  • Transaction T1 (in order): read P; read Q; if P = 0 then Q := Q + 1; write Q.

  • Transaction T2 (in order): read Q; read P; if Q = 0 then P := P + 1; write P.

  • In any non-serial interleaving where the transactions overlap, T1's read of P happens before T2's eventual write of P, producing a read–write conflict and an edge from the transaction that read P to the transaction that later writes P.

  • Similarly, T2's read of Q happens before T1's eventual write of Q, producing a read–write conflict and an edge from the transaction that read Q to the transaction that later writes Q.

  • Concretely, the precedence (conflict) graph has an edge from T1 to T2 and an edge from T2 to T1, forming a cycle.

  • A cycle in the precedence graph means the schedule cannot be transformed into any serial schedule by swapping non-conflicting operations; therefore it is not conflict serializable.

Conclusion: Any non-serial interleaving of the two transactions yields the read/write conflicts that produce a cycle in the precedence graph, so such a schedule is not conflict serializable.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir