TMF Introduction (G06.24+)

TMF Application Programming
HP NonStop Transaction Management Facility (TMF) Introduction522414-001
5-7
Managing Deadlock
After the UNLOCKRECORD request, the locks are released immediately, but only for
the unchanged records; locks on updated records are held until the transaction is
either committed or backed out.
Using File Locks for Repeatable Access
If an application issues LOCKFILE in a transaction, updates records while it holds the
lock granted by LOCKFILE, and then issues UNLOCKFILE before issuing END-
TRANSACTION, the file lock is held until the transaction commits.
Managing Deadlock
Deadlock occurs when several transactions hold locks and request more locks on data
locked by another transaction. Planning applications requires considering how locks
affect concurrency and how to avoid deadlock. If deadlock occurs, the application
needs to detect it and take appropriate action.
In Figure 5-1, deadlock results from this sequence of row (record) locking operations:
1. Transaction T1 accesses and locks row A.
2. Transaction T2 accesses and locks row B.
3. Transaction T1 attempts to access and lock row B and has to wait.
4. Transaction T2 attempts to access and lock row A and has to wait.
In this example, neither transaction can proceed. This situation can be avoided by
setting a time limit on how long a statement should wait before being granted a lock
request for access: if a request exceeds the time limit, the statement times out.
Figure 5-1. Deadlock Example
T2
Debits Balance B $500,00
T1
Debits Balance A $100,00
CHECKING
BAL
A
Deadlock
BAL
B
Credit Balance ACredit Balance B
VST028.vsd