Composing transactions
When used correctly, transactional memory is a powerful tool for building concurrent applications that modify shared data. Nevertheless, no technology is a silver bullet, and neither is STM. In this section, we will study how to compose transactions in larger programs and learn how transactional memory interacts with other features of Scala. We investigate some of the caveats of STM, and go beyond transactional references and the atomic
statement blocks to show how to use STM more effectively.
The interaction between transactions and side effects
Previously, we learned that an STM may roll back and retry a transaction. An attentive reader might notice that retrying a transaction means re-executing its side effects. Here, the side effects are arbitrary reads and writes to regular object
fields and variables.
Sometimes, side effects are not a problem. Transactional references cannot be modified outside a transaction, and inside a transaction their modifications are aborted...