Book Image

Learning Concurrent Programming in Scala

By : Aleksandar Prokopec
5 (1)
Book Image

Learning Concurrent Programming in Scala

5 (1)
By: Aleksandar Prokopec

Overview of this book

Table of Contents (18 chapters)
Learning Concurrent Programming in Scala
Credits
Foreword
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Chapter 7. Software Transactional Memory

 

"Everybody who learns concurrency and thinks they understand it, ends up finding mysterious races they thought weren't possible, and discovers that they didn't actually understand it yet after all."

 
 --Herb Sutter

While investigating the fundamental primitives of concurrency in Chapter 2, Concurrency on the JVM and the Java Memory Model, we recognized the need for protecting parts of the program from shared access. We saw that a basic way of achieving this isolation is the synchronized statement, which uses intrinsic object locks to ensure that at most a single thread executes a specific part of the program at the same time. The disadvantage of using locks is that they can easily cause deadlocks, a situation in which the program cannot progress.

In this chapter, we will introduce Software Transactional Memory (STM), a concurrency control mechanism for controlling access to shared memory, which greatly reduces the risk of deadlocks and races. An STM...