"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message > It's thread-safe
in terms of *acquiring* the singleton - it doesn't
mean that methods within the type are automatically thread-safe. To be
honest, I don't know how/whether remoting affects this at all.
Thank you so much for responding. I have gained a tremendous amount from
your posts and your articles. They are incredible clear. Your baby is cute
too :-)
I do understand that methods of the singleton need to use locks if they
access a resource. I guess what I still don't understand is what is it
actuially, that makes the aquiring the instance thread-safe.
You say "static constructors in C# are specified to execute only when an
instance of the class is created or a static member is referenced, and to
execute only once per AppDomain"
In the abbreviated version, the static constructor is removed. Is the
static type initialization executed only once as well? Is that what
guarantees the thread-safety?
As regards remoting, I am not traversing AppDomains, but I am going to be
intercepting calls using ContextBoundObject. I access the Singleton from a
ServerContextSink. I don't know whether it would be safer to use the
implementation below.
private static Singleton Instance
{
get
{
if (instance == null)
lock (typeof(Singleton))
if (instance == null)
instance = new Singleton();
return instance;
}
}
Thanks again for all your help.
Robert Zurer