In the previous section, I recommended using one lock per shared resource. We also saw that sometimes we cannot do such fine-grained locking and that we have to implement locks that protect more than one resource at the same time.
The lock striping pattern covers the opposite case. Sometimes, one lock per resource is not enough. On some occasions, we may want to implement multiple locks for one shared resource. We could, for example, add a lock to each element in an array or list.
Imagine the fitting rooms in a clothing store. They are not protected with one master lock as that would prevent multiple customers from trying out clothes at the same time. Rather, each room has its own lock.
This pattern can only be applied when the size of the shared resource is not modified during the execution. It does not help us if we lock two elements in an array and then another...