1,801 views
Consider the following schedules involving two transactions.

$S_1 : R_1(x), W_2(y),R_2(x),W_1(y), \ commit_1, \ commit_2$

$S_2 : R_1(x), R_2(y),W_1(z), \ commit_1,R_3(y), R_3(z), W_2(y), W_3(x), commit_2, commit_3$

Which of the following statements is true?

A) Both S1 and S2 are allowed under 2PL
B) only S1 is allowed under 2PL
C) only S2 is allowed under 2PL
D)  neither S1 nor S2 is allowed under 2PL

whats ur reason ?
once we start unlocking  we are not going to lock any variable again
but where are we doing this ? did u saw minipandas comment ?

S1 is 2PL which can be seen easily in Fig.1.

The main problem is in the step that I have marked in the Fig.2 for schedule S2, which is that whether we can apply lock on X where it is applied in transaction 3. According to me, I have seen no such restriction, therefore S2 should be 2PL. If anyone knows anything about this, please do share in the comments.

D will be the answer because S2 will obtain all the locks in the growing phase and S1 can't do anything till S2 releases locks but we can see an overlap so both are not allowed for 2 phase locking protocol.
by

For S1

T1 T2
S(x)
X(y)
Write(y)
S(x)
U(x)
U(y)
X(y)
U(y)
U(y)
commit
Commit

For S2

T1 T2 T3
S(x)
S(y) , **
X(z)
Write(z)
commit
U(z)
U(x)
S(y)
S(z)
X(x)
U(y)
#
Write(y)
Write(x)
U(x)
U(z)
commit

Here S1 is under 2PL.

For S2 there is two possibility where it violates the 2PL property.

First possibility is

# : Here in transaction T2 of S2, to write on Y we have to apply exclusive lock on Y but we can not do that as we have already applied  shared lock on Y during initial read on Y. So we can not apply exclusive lock.

Second possibility is

** : Here in transaction T2 of S2, we can apply exclusive lock on Y to read and write. But after applying this lock we can not apply lock on Y in transaction T3 to read Y.

Due to above condition S2 is not under 2PL.

So answer is option (C) Only S1 is allowed under 2PL.

S1: It satisfies 2PL

 T1 T2 SL(X) SL(X) R(X) XL(Y) W(Y) U(Y) XL(Y) R(X) U(X) W(Y) U(X) U(Y)