When writing thread-safe classes, the main issue is to separate the data into multiple independent parts — and to choose the right size for those parts. If the part is too small, our class is not thread-safe. If the part is too large, the class is not scalable.
You may also like: 7 Techniques for Thread-Safe Classes
Let us look at an example that further illustrates this scenario: