234
In Figure 12-5, time is shown in the y axis with time progressing downward. These
operations occur in the following order:
• Assume X=0 when the application starts.
• A main() function creates two threads: Thread 1 and Thread 2. Both
threads are intended to start their own transactions and acquire the
lock to modify X.
• Since Thread 1 runs first, it acquires the lock on X first. It then
adds the X variable to the transaction before incrementing X by 5.
Transparent to the program, the value of X (X=0) is added to the undo
log when X was added to the transaction. Since the transaction is not
yet complete, the application has not yet explicitly flushed the value.
• Thread 2 starts, begins its own transaction, acquires the lock, reads
the value of X (which is now 5), adds X=5 to the undo log, and
increments it by 5. The transaction completes successfully, and
Thread 2 flushes the CPU caches. Now, x=10.
Figure 12-5. The rollback mechanism for the unfinished transaction in Thread 1
is also overriding the changes made by Thread 2, even though the transaction for
Thread 2 finishes correctly
Chapter 12 Debugging persistent MeMory appliCations
Précédent

- 258/457

Suivant