Beruflich Dokumente
Kultur Dokumente
A I only
B II only
C Both I and II
D Neither I nor II
Question 2 Explanation:
2 Phase Locking (2PL) is a concurrency control method that guarantees
serializability. The protocol utilizes locks, applied by a transaction to data, which
may block (interpreted as signals to stop) other transactions from accessing the
same data during the transactions life. 2PL may be lead to deadlocks that result
from the mutual blocking of two or more transactions. See the following situation,
neither T3 nor T4 can make progress.
Question 4 Explanation:
Basic two phase locking protocol ensures only conflict serializability and strict two
phase locking protocol ensures recoverability as well. So statement A is correct.
Checkpoints are inserted to minimize the task of undo-redo in recoverability. So,
statement B is not correct. Hence correct option B is correct choice.
Lock-x(A)
Read(A)
A=A-50
write(A)
Unlock(A)
Lock-s(B)
Read(B)
Unlock(B)
Lock-s(A)
Read(A)
Unlock(A)
Display(A+B)
Read(B)
Lock-x(B)
B=B+50
write(B)
Unlock(B)
So above we have shown one interleaving and we could understand the data flow by
below example:
Output:
Let say in the start of the schedule A=100 and B=200 so in total we should have 300
always.
But as we see that after Till Display (B+A) we have A=50 and B=200 to total=250 but
it should be 300 to make consistency.
SOLUTION:
a. Lock and unlock instructions:
T34: lock-S(A)
read(A)
lock-X(B)
read(B)
if A = 0
then B := B + 1
write(B)
unlock(A)
unlock(B)
T35: lock-S(B)
read(B)
lock-X(A)
read(A)
if B = 0
then A := A + 1
write(A)
unlock(B)
unlock(A)
b. Execution of these transactions can result in deadlock. For example, consider the
following partial schedule:
QUESTION:
Consider the timestamp-ordering protocol, and two transactions, one that
writes two data items p and q, and another that reads the same two data
items. Give a schedule whereby the timestamp test for a write operation
fails and causes the first transaction to be restarted, in turn causing a
cascading abort of the other transaction. Show how this could result in
starvation of both transactions. (Such a situation, where two or more
processes carry out actions, but are unable to complete their task because
of interaction with the other processes, is called a livelock.)
Let TS(T1) < TS(T2) and let the timestamp test at each operation except
write(q) be successful. When transaction T1 does the timestamp test for
write(q) it finds that TS(T1) < R-timestamp(q), since TS(T1) < TS(T2) and
R-timestamp(q) = TS(T2). Hence the writeoperation fails and transaction
T1 rolls back. The cascading results in transaction T2 also being rolled back
as it uses the value for item p that is written by transaction T1.
If this scenario is exactly repeated every time the transactions are restarted,
this could result in starvation of both transactions.