Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Patterns.Threading
- {
- /// <summary>
- /// Singleton Design Pattern for multi-thread environment
- /// </summary>
- /// <remarks>Uses double-checked locking method - effective but expensive locking mechanism with least control.</remarks>
- public sealed class DoubleLockSingleton
- {
- private static readonly object _sync = new object();
- private static DoubleLockSingleton _instance;
- private DoubleLockSingleton()
- {
- }
- public static DoubleLockSingleton Instance
- {
- get
- {
- if (_instance != null)
- return _instance;
- lock( _sync )
- {
- _instance = new DoubleLockSingleton();
- return _instance;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment