Another problem with two-phase locking, which applies to all locking-based schemes,
is that it can cause deadlock , since transactions can wait for locks on data items. If
two transactions wait for locks on items held by the other, deadlock will occur and the
deadlock detection and recovery scheme described in the Section 20.2.4 is needed. It is
also possible for transactions to be in livelock, that is left in a wait state indefinitely,
unable to acquire any new locks, although the DBMS is not in deadlock. This can happen
if the waiting algorithm for transactions is unfair and does not take account of the time that
transactions have been waiting. To avoid livelock, a priority system can be used, whereby
the longer a transaction has to wait, the higher its priority, for example, a first-come-first-served queue can be used for waiting transactions.