Anda di halaman 1dari 10

Solusi Latihan Slide 12

PHG –SBD 19/20 – 2


Slide 22
Consider the following two transactions:

Exercise
1. Add lock and unlock instructions to transactions T1 and T2 so
that they observe the two-phase locking protocol.
2. Can the execution of these transactions result in a deadlock?
T1 T2
Lock-S (A)
Lock-X (B)
Growing Phase
Read (A)
Read (B)
If A=0 then B := B+1

Solusi Write (B)


Lock-S (B)
No. 1 Lock-X (A)
Schedule 1 Unlock (A)

(Basic 2PL) Unlock (B)


Read (B)
Read (A)
Shrinking Phase
If B=0 then A := A+1
Write (A)
Unlock (B)
Unlock (A)
T1 T2
Lock-S (A)
Lock-X (B)
Growing Phase
Lock-S (B)
Lock-X (A)
Read (A)

Solusi Read (B)


If A=0 then B := B+1
No. 1 Write (B)
Schedule 2 Unlock (A)

(Basic 2PL) Unlock (B)


Read (B)
Read (A)
Shrinking Phase
If B=0 then A := A+1
Write (A)
Unlock (B)
Unlock (A)
 Schedule 1 tidak terjadi deadlock
No. 2  Schedule 2 tidak terjadi
Latihan Soal
Concurrency Control
PHG –SBD 23/24-2
T1 T2 T3 T4
Lock-s (y)
1. Analisis schedule di samping Kondisi
read (y)
lock-s (y)
apakah yang terjadi berdasarkan
read (y)
schedule tersebut?
unlock(y) 2. Mengapa hal tersebut bisa terjadi?
lock-x (y) 3. Apakah yang harus dilakukan untuk
write (y) mencegah kondisi tersebut?
lock-x (z) 4. Apakah yang dapat dilakukan untuk
write (z) mengatasi kondisi tersebut?
lock-s (z)
1 unlock (y)
read (z)

unlock (z)
lock-s (z)
read (z)
unlock (z)
lock-s (y)
read (y)
unlock (y)
lock-s (x)
read (x)
... ... ... ...
T1 T2
lock-X (Q)
read (Q) 1. Analisis schedule , Apakah terjadi
lock-S (P) deadlock pada schedule tersebut?
lock-S (P)
Ya, jelaskan pada bagian mana kondisi
read (P )
read (P)
deadlock terjadi! Bagaimana cara mengatasi
lock-X (Q) deadlock tersebut!
lock-S (R ) Tidak, jelaskan proses pengaturan
lock-S (R ) concurrent transactions yang terjadi pada
write (Q) schedule di atas!
2 unlock (Q)
read (R )
lock-X (R )
unlock (P)
write (R )
read (R )
lock-X (P)
unlock (R )
write (Q)
unlock (P)
unlock (Q)
unlock (R )
unlock (P)
T1 T2
Read (X)
Write (Y)
a. Buatlah schedule yang menerapkan
Read (Y)
strict two-phase locking protocol pada
Read (X)
schedule Tx!
Write (X)
Write (X)
b. Apakah mungkin terjadi deadlock pada
schedule yang sudah Anda buat?
Read (X)
Read (Z) c. Jelaskan keterpenuhan strict two-
3 Write (Z) phase locking protocol pada schedule
Write (Y) yang sudah Anda buat!
Write (Z)
Read (Y) d. Buktikan apakah schedule yang sudah
Write (X) Anda buat memungkinkan/tidak
Read (X) memungkinkan terjadinya deadlock!
Write (X)
Read (X)

Anda mungkin juga menyukai