Atomicity violation
As mentioned in the first chapter, there is a type of concurrency error called atomicity violation. This type of error happens when the state of an object is modified concurrently without correct synchronization. The example that we saw in the first chapter was pretty simple: many coroutines modified the state of an object from different threads, and this resulted in some of those modifications being lost.
This type of error can happen with Kotlin too, but the language offers primitives that will help you to use the right design so that you avoid atomicity violation.
First, we need to truly understand what atomicity means and how violations can happen. Then we will be able to understand how to write our code to make it ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access