Previous | Next --- Slide 37 of 65
Back to Lecture Thumbnails
rootB

These two transactions have RW conflicts, so if one proceed, the other detects the conflict and has to abort and restart the transaction. This will cause a live lock.

BestBunny

If synchronized is replaced with atomic, the instructions in only one of the two threads will be running at the same time. The atomic region would have to be completed before any context switches occur (or restore to the initial state in a TM implementation which would result in the behavior explained by @rootB). For example, if Thread 2 begins the atomic region, it will complete it's atomic region before Thread 1 performs its atomic region. As a result, if flagA and flagB are initially false, whichever of the threads begins execution initially will loop forever on the while (...) line because the write required for the loop to end would not occur before the completion of the atomic region.