Kotlin offers plenty of tools that can be used to write concurrent code safely. In the previous chapter, we talked about channels in the context of collaborative concurrency; in this chapter, we will dive into more tools that can be used to avoid sharing states between threads. We will start by talking again about atomicity violation, and then we will talk about ways of avoiding it. This chapter presents many topics in the context of atomicity violation, but it's important to understand that they can be used in other scenarios – for example, you can prevent race conditions using the methods covered in this chapter as well.
Let's take a look at the topics that we will cover in this chapter:
- Atomicity violation recap
- Thread confinement
- When and how to use thread confinement for safe concurrency
- Actors
- How actors work and...