Edit

IS633 Discussion 11

Postach.io USMBC IS633 published

Question 1

Problem 1: Does the following schedule satisfy two-phase locking protocol?

step T1 T2 T1 Phase T2 Phase
1 Lock-X(A) Growing
2 Read(A) Growing
3 A := A – 50 Growing
4 Write(A) Growing
5 Lock-S(B) Growing
6 Read(B) Growing
7 Unlock(B) Shrinking
8 Print(B)
9 Lock-X(B) Growing
10 Unlock(A) Shrinking
11 Read(B) Shrinking
12 B : = B + 50 Shrinking
13 Write(B) Shrinking
14 Unlock(B) Shrinking

Two-phase locking protocol is pretty simple. It just takes the transaction and divides it into two parts; growing and shriking phases. The Growing phase is where the transaction can obtain but not release locks. The Shrinking phase is where may release but not obtain locks. The shrinking phase always follows the growing phase.

As you can see from the above table each transaction clearly has a growing phase followed by a shrinking phase. This means that our table satisfies two-phase locking protocol!

Question 2

Does the following schedule have a deadlock?

step T1 T2 T3
1 Lock-X(A)
2 Write(A)
3 Lock-X(B)
4 Write(B)
5 Lock-X(C)
6 Write(C)
7 Lock-S(A)
8 Lock-S(C)
9 Lock-S(B)

Deadlocks occur when two processes are waiting for resources which the other process is currently holding that resource.

That is what is occuring here;

  • T1 is holding resource A which T3 is waiting for
  • T3 is holding resource C which T2 is waiting for
  • T2 is holding resource B which T1 is waiting for
%23%20IS633%20Discussion%2011%0A@%28Postach.io%29%5BUSMBC%2C%20IS633%2C%20published%5D%0A%0A%0A%23%23%20Question%201%0A**Problem%201%3A%20%20Does%20the%20following%20schedule%20satisfy%20two-phase%20locking%20protocol%3F**%0A%0Astep%20%7C%20T1%20%7C%20T2%20%7C%20T1%20Phase%20%7C%20T2%20Phase%0A-%7C-%7C-%7C-%7C-%0A1%20%7C%20Lock-X%28A%29%20%7C%7C%20Growing%20%0A2%20%7C%20Read%28A%29%20%7C%7C%20Growing%0A3%20%7C%20A%20%3A%3D%20A%20%u2013%2050%20%7C%7C%20Growing%20%0A4%20%7C%20Write%28A%29%20%7C%7C%20Growing%0A5%20%7C%7C%20Lock-S%28B%29%20%7C%7C%20Growing%0A6%20%7C%7C%20Read%28B%29%20%7C%7C%20Growing%0A7%20%7C%7C%20Unlock%28B%29%20%7C%7C%20Shrinking%0A8%20%7C%7C%20Print%28B%29%20%7C%7C%20%0A9%20%7C%20Lock-X%28B%29%20%7C%7C%20Growing%20%0A10%20%7C%20Unlock%28A%29%20%7C%7C%20Shrinking%0A11%20%7C%20Read%28B%29%20%7C%7C%20Shrinking%0A12%20%7C%20B%20%3A%20%3D%20B%20+%2050%20%7C%7C%20Shrinking%0A13%20%7C%20Write%28B%29%20%7C%7C%20Shrinking%0A14%20%7C%20Unlock%28B%29%20%7C%7C%20Shrinking%0A%0A%0ATwo-phase%20locking%20protocol%20is%20pretty%20simple.%20It%20just%20takes%20the%20transaction%20and%20divides%20it%20into%20two%20parts%3B%20growing%20and%20shriking%20phases.%20The%20Growing%20phase%20is%20where%20the%20transaction%20can%20obtain%20but%20not%20release%20locks.%20The%20Shrinking%20phase%20is%20where%20may%20release%20but%20not%20obtain%20locks.%20The%20shrinking%20phase%20always%20follows%20the%20growing%20phase.%20%0A%0AAs%20you%20can%20see%20from%20the%20above%20table%20each%20transaction%20clearly%20has%20a%20growing%20phase%20followed%20by%20a%20shrinking%20phase.%20This%20means%20that%20our%20table%20satisfies%20two-phase%20locking%20protocol%21%0A%0A%23%23%20Question%202%0A**Does%20the%20following%20schedule%20have%20a%20deadlock%3F**%0A%0A%0Astep%20%7C%20T1%20%7C%20T2%20%7C%20T3%0A-%7C-%7C-%7C-%0A1%20%7C%20Lock-X%28A%29%0A2%20%7C%20Write%28A%29%0A3%20%7C%7C%20Lock-X%28B%29%0A4%20%7C%7C%20Write%28B%29%0A5%20%7C%7C%7C%20Lock-X%28C%29%0A6%20%7C%7C%7C%20Write%28C%29%0A7%20%7C%7C%7C%20Lock-S%28A%29%0A8%20%7C%7C%20Lock-S%28C%29%0A9%20%7C%20Lock-S%28B%29%0A%0ADeadlocks%20occur%20when%20two%20processes%20are%20waiting%20for%20resources%20which%20the%20other%20process%20is%20currently%20holding%20that%20resource.%20%0A%0AThat%20is%20what%20is%20occuring%20here%3B%20%0A-%20T1%20is%20holding%20resource%20A%20which%20T3%20is%20waiting%20for%20%0A-%20T3%20is%20holding%20resource%20C%20which%20T2%20is%20waiting%20for%20%0A-%20T2%20is%20holding%20resource%20B%20which%20T1%20is%20waiting%20for%20%0A%0A%60%60%60sequence%0AT1--%3ET3%3A%20holding%20A%2C%20blocking%0AT3--%3ET2%3A%20holding%20C%2C%20blocking%0AT2--%3ET1%3A%20holding%20B%2C%20blocking%0A%60%60%60%0A%0A%0A