Strategies for Effective Concurrency
On one hand, we want to ensure consistency and accuracy when using concurrency. On the other hand, we want to ensure we’re getting as much performance as possible on the given hardware. In this chapter, we looked at ways to meet both these goals.
We can easily avoid race conditions or consistency issues once we fully eliminate shared mutable state. When threads don’t compete to access mutable data, there’s no issue of visibility and crossing the memory barrier. We also don’t have to worry about controlling the execution sequence of threads; since they don’t compete, there are no mutually exclusive sections to safeguard in code.
Provide shared immutability where possible. Otherwise, follow isolated mutability—ensure ...
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