Created
March 5, 2014 10:59
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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