Client-side locking
In that case where each instance of ListHelper
would contain its own list you could make that list private and just synchronize on the ListHelper
instance. I guess this is a somewhat constructed example to make a point with as little code as possible. IMO the name ListHelper
would imply that I could pass an external list which could clearly be reused by multiple ListHelper
instances.
I'd say the point is: given the code as it is and without changing visibility of list
(could break other code) you better synchronize on list
than the current ListHelper
instance.