Atomics – the Primitives of Synchronization

In Chapter 4, Sync and Send – the Foundation of Rust Concurrency, and Chapter 5, Locks – Mutex, Condvar, Barriers and RWLock, we discussed the fundamentals of lock-based concurrency in Rust. However, there are some cases where lock-based programming is not suitable, such as when extreme performance is a concern or threads may never block. In such domains, the programmer must rely on the atomic synchronization primitives of modern CPUs.

In this chapter, we'll be discussing the atomic primitives available to the Rust programmer. Programming with atomics is a complex topic and an area of active research. An entire book could be dedicated to the topic of atomic Rust programming. As such, we'll be shifting our tactics slightly for this chapter, focusing on more of a tutorial style than previous chapters where we've done deep dives on existing software. Everything presented in the prior chapters will come to bear here. By the end of this chapter, you ought to have a working understanding of atomics, being able to digest existing literature with more ease and validate your implementations.

By the end of this chapter, we will have:

  • Discussed the concept of linearizability
  • Discussed the various atomic memory orderings, along with their meanings and implications
  • Built a mutex from atomic primitives
  • Built a queue from atomic primitives
  • Built a semaphore
  • Made clear the difficulties of memory reclamation in an atomic context
..................Content has been hidden....................

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