[Mono-devel-list] What to do with TypeInitialization in case of exceptions on second attempt to access class ? Singleton pattern
Rafael Teixeira
monoman at gmail.com
Mon Oct 25 17:01:46 EDT 2004
If you need it to be thread-safe surround with the appropriate guarding code:
public static Singleton Instance {
get {
lock (typeof(Singleton)) {
if (Singleton.instance == null)
Singleton.instance = new Singleton();
return Singleton.instance;
}
}
}
On Mon, 25 Oct 2004 23:39:55 +0300, Andriy G. Tereshchenko
<mono-list at spam.24.odessa.ua> wrote:
> > Possibly Rafael Teixeira, possibly on Rafael Teixeira wrote possibly this:
> > public static Singleton Instance {
> > get {
> > if (Singleton.instance == null)
> > Singleton.instance = new Singleton();
> > return Singleton.instance; }
> > }
>
> This is not thread-safe. Period.
>
> --
>
>
> Andriy G. Tereshchenko
> Odessa, Ukraine
>
>
--
Rafael "Monoman" Teixeira
---------------------------------------
Just the 'crazy' me in a sane world, or would it be the reverse? I dunno...
More information about the Mono-devel-list
mailing list