This chapter opened with the topic of Concurrency patterns by exploring five different patterns related to managing access to shared data from multiple threads.
We learned that the lock pattern ensures that two threads are not trying to modify shared data or an object at the same time. It is also useful when one thread is reading from a shared object while another wants to modify it. We explored three different implementations of this pattern and compared their advantages and disadvantages.
We also learned that the lock pattern can be improved by introducing lock striping—a pattern that further fragments data inside one object and protects it with multiple locks instead of one. This approach is useful when we manipulate data in a list or array and don't add or remove existing elements. We explored two use possibilities, adding an array of locks or using one unused bit of existing data in combination with a custom locking solution.
After that, we spent some time exploring the lazy creation...