7,645 views
3 votes
3 votes
How to check if a schedule is allowed in 2PL or not?

S1:R2(A)W1(B)W1(C)R3(B)R2(B)R1(A)R2(C)W3(A)

S2:W2(A)W1(A)W3(A)W2(B)W1(B)W3(B)

2 Answers

6 votes
6 votes

Schedule: A predefined timely order execution of two or more transaction. The order of execution has to be maintained.

  S1:R2(A)W1(B)W1(C)R3(B)R2(B)R1(A)R2(C)W3(A)  
T1 T2 T3
  Lock_R(A)  
  R(A)  
Lock_X(B)    
W(B)    
Lock_X(C)    
W(C)    
Lock_R(A)    
Unlock(B)    
Unlock(C)    
    Lock_R(B)
    R(B)
  Lock_R(B)  
  R(B)  
R(A)    
U(A)    
  Lock_R(C)  
  R(C)  
    Lock_X(A)
    W(A)

Therefore, S1 can definitely allowed in 2PL.

S2:W2(A)W1(A)W3(A)W2(B)W1(B)W3(B)

T1 T2 T3
  Lock_X(A)  
  W(A)  
  Lock_X(B)  
  Unlock(A)  
Lock_X(A)    
W(A)    
Lock_X(B) //denied    
     
     
     
  W(B)  

Because in T2, Lock_X(B) has to be acquired in growing phase as T2 wants to W(B) (see in the given schedule), when T1 wants Lock_X(B) it is denied because T2 has it for W(B) operation later. Therefore, Transaction wont progress any further.
Some people might be having doubt that T2 has all the locks then why doesn't T2 completes its execution first by W(B) and release Lock(B), you are conceptually right but the problem is you are given a SCHEDULE in which order has to be maintained. If the task was you were given 3 transactions and you were asked whether there can a schedule possible which is allowed in 2PL then you can design such schedule, but here you are asked whether this schedule will pass through 2PL or not and the answer is NO. S2 is not allowed in 2PL, though it is Conflict Serializable, you can check by drawing precedence graph it will be an acyclic graph and you can find a topological order which is conflict equal to one of the serial schedules of S2.

2 votes
2 votes

both are allowed in 2PL.

Related questions

0 votes
0 votes
1 answer
1
1 votes
1 votes
3 answers
3
learncp asked Sep 18, 2015
1,512 views
Suppose we have a schedule containing two transactions  as shown-$\begin{bmatrix} T1 & T2 \\ R(A) & \\ W(A) & \\ & R(A) \\  & W(A) \\ R(B)& \\ W(B)& \\ & R(B) \\  & W(...
1 votes
1 votes
1 answer
4
gate-17 asked Jul 27, 2016
402 views