Thread Confinement, Actors, and Mutexes

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 when to use them
  • Mutual exclusion
  • How to use mutual exclusion
  • Volatile variables
  • When to use volatile variables
  • Atomic variables

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.104.242