📄 deadlock.so
字号:
m4_comment([$Id: deadlock.so,v 10.20 2002/06/24 14:51:07 bostic Exp $])m4_ref_title(m4_tam Applications, Deadlock detection, deadlock detection in @transaction protected applications, transapp/admin, transapp/checkpoint)m4_p([dnlThe first component of the infrastructure, m4_italic(deadlockdetection), is not so much a requirement specific totransaction-protected applications, but instead is necessary for almostall applications in which more than a single thread of control will beaccessing the database at one time. Even when m4_db automaticallyhandles database locking, it is normally possible for deadlock to occur.Because the underlying database access methods may update multiple pagesduring a single m4_db API call, deadlock is possible even when threadsof control are making only single update calls into the database. Theexception to this rule is when all the threads of control accessing thedatabase are read-only or when the m4_cam product is used; the m4_camproduct guarantees deadlock-free operation at the expense of reducedconcurrency.])m4_p([dnlWhen the deadlock occurs, two (or more) threads of control each requestadditional locks that can never be granted because one of the threadsof control waiting holds the requested resource. For example, considertwo processes: A and B. Let's say that A obtains a write lock on itemX, and B obtains a write lock on item Y. Then, A requests a lock on Y,and B requests a lock on X. A will wait until resource Y becomesavailable and B will wait until resource X becomes available.Unfortunately, because both A and B are waiting, neither will releasethe locks they hold and neither will ever obtain the resource on whichit is waiting. For another example, consider two transactions, A andB, each of which may want to modify item X. Assume that transaction Aobtains a read lock on X and confirms that a modification is needed.Then it is descheduled and the thread containing transaction B runs.At that time, transaction B obtains a read lock on X and confirms thatit also wants to make a modification. Both transactions A and B willblock when they attempt to upgrade their read locks to write locksbecause the other already holds a read lock. This is a deadlock.Transaction A cannot make forward progress until Transaction B releasesits read lock on X, but Transaction B cannot make forward progress untilTransaction A releases its read lock on X.])m4_p([dnlIn order to detect that deadlock has happened, a separate process orthread must review the locks currently held in the database. Ifdeadlock has occurred, a victim must be selected, and that victim willthen return the error m4_ref(DB_LOCK_DEADLOCK) from whatever m4_db callit was making. m4_db provides a separate UNIX-style utility that canbe used to perform this deadlock detection, named m4_ref(db_deadlock).Alternatively, applications can create their own deadlock utility orthread using the underlying m4_ref(lock_detect) function, or specifythat m4_db run the deadlock detector internally whenever there is aconflict over a lock (see m4_ref(dbenv_set_lk_detect) for moreinformation). The following code fragment does the latter:])include(ref/transapp/deadlock.cs)m4_p([dnlDeciding how often to run the deadlock detector and which of thedeadlocked transactions will be forced to abort when the deadlock isdetected is a common tuning parameter for m4_db applications.])m4_page_footer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -