Chapter 8. Many cooks in the kitchen: Thread safety

This chapter covers

  • Recognizing and avoiding deadlocks and race conditions
  • Using explicit locks
  • Using lock-free synchronization
  • Designing immutable classes

The plan for this chapter is to make your implementation thread-safe. For a class to be thread-safe, multiple threads should be able to interact with the objects of that class with no explicit synchronization. In other words, a thread-safe class takes care of the synchronization issues. The clients can just freely invoke any class method, even simultaneously on the same object, with no adverse effects. The design-by-contract methodology I presented in chapter 5 allows you to precisely characterize what an adverse effect would be: the violation ...

Get Seriously Good Software now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.