I've the following code. It may be dumb question, but I'm not sure, if synchronization is necessary or not.
class MyClass
{
[ThreadStatic]
private static object _staticObject;
private static readonly LockStaticField = new object();
public static object StaticObject
{
get
{
lock(LockStaticField)
{
return _staticObject ?? (_staticObject = new object());
}
}
}
}
I know ThreadStatic
fields doesn't need any synchronization because the state is not shared. But what is about the static getter and the initialization?