Limitations of STM

STM eliminates explicit synchronization. We no longer have to worry if we forgot to synchronize or if we synchronized at the wrong level. There are no issues of failing to cross the memory barrier or race conditions. I can hear the shrewd programmer in you asking “What’s the catch?” Yes, STM has limitations—otherwise, this book would’ve ended right here. It’s suitable only when write collisions are infrequent. If our application has a lot of write contention, we should look beyond STM.

Let’s discuss this limitation further. STM provides an explicit lock-free programming model. It allows transactions to run concurrently, and they all complete without a glitch where there are no conflicts between them. This provides for greater ...

Get Programming Concurrency on the JVM now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.