Sei sulla pagina 1di 3

King Saud University

Collage of computer and information sciences


Information systems department

Tutorial 6
Exercise 1:

Which of the following schedules is conflict serializable? For each serializable schedule, determine the
equivalent serial schedules:

(a) r1(X), r3(X), w1(X), r2(X), w3(X).


(b) r1(X), r3(X), w3(X), w1(X), r2(X).
(c) r3(X), r2(X), w3(X), r1(X), w1(X).
(d) r3(X), r2(X), r1(X), w3(X), w1(X).

Answer 1:

(a) r1(X), r3(X), w1(X), r2(X), w3(X).


There are two cycles. It is not conflict serializable.

T1 T2

T3

(b) r1(X), r3(X), w3(X), w1(X), r2(X).


There is one cycle. It is not conflict serializable.
T1 T2

T3
(c ) r3(X), r2(X), w3(X), r1(X), w1(X).
There are NO cycles. This schedule is serializable.

T1 T2

T3

The schedule is equivalent to:


r2(X), r3(X), w3(X), r1(X), w1(X).
(T2 -> T3 -> T1)

(d) r3(X), r2(X), r1(X), w3(X), w1(X).


There is one cycle. It is not conflict serializable.

T1 T2

T3
Exercise 2:

Consider the following transactions:


T1: read(A), read(B), B = A + 1 , write(B)
T2: read(B), read(A), A = B + 1 , write(A)

a) Rewrite T1 and T2 so they follow the 2PL protocol.


b) Give an incomplete schedule of these two transactions that can result in a dead lock.

Answer 2:

T1: s1(A), r1(A), x1(B), r1(B), B = A + 1, w1(B), u1(A), u1(B).


T2: s2(B), r2(B), x2(A), r2(A), A = B + 1, w2(A), u2(B), u2(A).

T1 T2
1 s1(A)
2 r1(A)
3 s2(B)
4 r2(B)
5 x1(B) * T1 has A and is waiting for B
6 r1(B)
7 x2(A) * T2 has B and is waiting for A (DEADLOCK)
8 r2(A)
9 B=A+1
10 w1(B)
11 A=B+1
12 w2(A)
13 u1(A)
14 u1(B)
15 u2(B)
16 u2(A)

Potrebbero piacerti anche