跳过正文

数据库-事务作业

·149 字· loading · loading ·
Masterlong
作者
Masterlong
熬夜,但是世界之夜
数据库系统 - 这篇文章属于一个选集。
§ 9: 本文

事务
#

Consider the following two transactions:

𝑇34

𝑟𝑒𝑎𝑑(𝐴)

𝑟𝑒𝑎𝑑(𝐵)

𝑖𝑓 𝐴 = 0 𝑡ℎ𝑒𝑛 𝐵 ∶= 𝐵 + 1;

𝑤𝑟𝑖𝑡𝑒(𝐵)

𝑇35

𝑟𝑒𝑎𝑑(𝐵)

𝑟𝑒𝑎𝑑(𝐴)

𝑖𝑓 𝐵 = 0 𝑡ℎ𝑒𝑛 𝐴 ∶= 𝐴 + 1;

𝑤𝑟𝑖𝑡𝑒(𝐴)

Add lock and unlock instructions to transactions T31 and T32 so that they observe the two-phase locking protocol. Can the execution of these transactions result in a deadlock?

答:此时满足两阶段锁协议:

T34:

lock(A) // Acquire a lock on A read(A) lock(B) // Acquire a lock on B read(B) if A = 0 then B := B + 1 write(B) unlock(B) // Release the lock on B unlock(A) // Release the lock on A

T35:

lock(B) // Acquire a lock on B read(B) lock(A) // Acquire a lock on A read(A) if B = 0 then A := A + 1 write(A) unlock(A) // Release the lock on A unlock(B) // Release the lock on B

观察到不存在循环依赖或者获取锁的冲突。所以不存在死锁现象。

数据库系统 - 这篇文章属于一个选集。
§ 9: 本文

相关文章

数据库-实体关系模型
·29 字· loading · loading
数据库-5
·120 字· loading · loading
数据库-4作业
·401 字· loading · loading