Consider the following two transactions T1 and T2

T1: read(A)

Read(B)

If A=0 then B=B+1

Write(B)

T2: read(B)

Read(A)

If B≠0 then A=A-1

Write(A)

Which of the following scheme using shared and exclusive locks, satisfy the requirements for strict two phase locking for the above transactions?

1

S1

S2

Lock S(A)

Lock S(B)

Read(A)

Read(B)

Lock S(B)

Lock S(A)

Read (B)

Read (A)

If A=0 then B=B+1

If B≠0 then A=A-1

Write(B)

Write(A)

commit

Commit

Unlock(A)

Unlock(B)

Unlock(B)

Unlock(A)

2

S1

S2

Lock X(A)

Lock X(B)

Read(A)

Read(B)

Lock X(B)

Lock X(A)

Read (B)

Read (A)

If A=0 then B=B+1

If B≠0 then A=A-1

Write(B)

Write(A)

Unlock(A)

Unlock(A)

commit

Commit

Unlock(B)

Unlock(B)

3

S1

S2

Lock S(A)

Lock S(B)

Read(A)

Read(B)

Lock X(B)

Lock X(A)

Read (B)

Read (A)

If A=0 then B=B+1

If B≠0 then A=A-1

Write(B)

Write(A)

Unlock(A)

Unlock(B)

commit

Commit

Unlock(B)

Unlock(A)

4

S1

S2

Lock S(A)

Lock S(B)

Read(A)

Read(B)

Lock X(B)

Lock X(A)

Read (B)

Read (A)

If A=0 then B=B+1

If B≠0 then A=A-1

Write(B)

Write(A)

Unlock(A)

Unlock(A)

Unlock(B)

Unlock(B)

commit

commit

Sponsored

hivanix.in

Visit

This quiz is brought to you by hivanix.in

🌐 Web App Development

Quick Navigation