When reading the MSDN documentation it always lets you know if a class is thread safe or not. My question is how do you design a class to be thread safe? I am not talking about calling the class with locking I am meaning I am working for Microsoft create XXX class\object and I want to be say it is “Thread Safe” what would I need to do?
Share
The easiest and most foolproof way of making a class thread safe is to make it immutable. The beauty of it is that you don’t ever have to bother with locking again.
Recipe: Make all instance variables
readonlyin C# (finalin Java).See this question as well.