in Databases edited by
923 views
1 vote
1 vote

Consider the following schedule for transactions T1, T2 , these transactions have two phase locking:

T1: lock- S(A)
Read (A)
Lock –X (B)
Read (B)
B = A +B
Write (B)
Unlock (A)    
 Unlock(B)
T2 lock-X(A)
Lock- S(B)
write (A)
Read (B)
Unlock(A)
Unlock(B)

$$\begin{array}{||l|} \hline T1: & \text{Lock_S(A)} \\ & \text{Read (A)} \\ & \text{Lock _X (B)} \\ & \text{Read (B)} \\ & \text{B = A + B} \\ & \text{Write (B)} \\ & \text{Unlock (A)} \\ &  \text{Unlock(B)}  \\ \hline T2: & \text{Lock_X(A)} \\ & \text{Lock_S(B)} \\&\text{Write(A)} \\ & \text{Read(B)} \\ & \text{Unlock(A)} \\ & \text{Unlock(B)}  \\ \hline \end{array}$$

Which one of the statements below is the correct statement about T1 and T2?

  1. T1 and T2 are deadlock free
  2. T1 and T2 results in a deadlock
  3. T1 and T2 are serial schedule
  4. none of the above
in Databases edited by
by
923 views

4 Comments

Thanks for the solution.. but when T1 has acquired shared lock on item A,so T2 can't initiate its transaction and in this way T1 completes all its steps and then T2 will start or vice versa.
0
0
No there is a starvation in this situation so when starvation occurs T2 have to wait indefinite time.. you consider case for resource B also ... thats why not serial order they complete.
0
0
Ok.Thanx.
0
0

2 Answers

1 vote
1 vote
Best answer

a) T1 and T2 are deadlock free

related thread:

https://www.facebook.com/groups/core.cs/permalink/1375317922500457/

selected by

4 Comments

@Bikram
there is not even starvation, at the moment one transaction finish its work other can complete its work. because it's a DB transaction which meant to be executed only once, it's not like a while loop instruction
1
1

1.Option C is not clear to me.T1->T2 or T2->T1 always possible without any deadlock.Why such option ??

2. I feel no starvation will be there 

Please explain someone.

 

1
1

We can see that the two transactions follow 2PL (acquires locks in growing phase and releases the locks in shrinking phase).

 

From the book Fundamentals of Database Systems 7th Edition by Navathe:

Page 788:

It can be proved  that if any transaction in a schedule follows the two-phase locking protocol, the schedule is guaranteed to be serializable

 

Hence I believe Option (C) is the answer 

0
0
1 vote
1 vote

As suggested by their names:-

  • Shared locks can coexist with other shared locks.
  • Exclusive locks can't coexist with any lock

Clearly, deadlock isn't a possibility here. Option A


The given schedule is not necessarily serial because suppose $T_2$ runs first; $T_2$ can execute up to the fifth line and after that when it unlocks A, $T_1$ can run it's first two lines.

Hence, not serial. 

Answer:

Related questions