Skip to content

Instantly share code, notes, and snippets.

@leafbird
Created March 5, 2014 10:59
Show Gist options
  • Save leafbird/9365160 to your computer and use it in GitHub Desktop.
Save leafbird/9365160 to your computer and use it in GitHub Desktop.
...One approach is to use an idiom referred to as Double-Check Locking [Lea99]. However, C# in combination with the common language runtime provides a static initialization approach, which circumvents these issues without requiring the developer to explicitly code for thread safety.
// from http://msdn.microsoft.com/en-us/library/ff650316.aspx
public sealed class Singleton
{
private static readonly Singleton instance = new Singleton();
private Singleton(){}
public static Singleton Instance
{
get
{
return instance;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment