CSharp - Singleton design pattern alternative approaches: Double checked locking

Introduction

The following Singleton design pattern alternative implementation is called Double checked locking.

using System;

public sealed class Singleton
{
    private static volatile Singleton instance;
    private static object lockObject = new Object();

    private Singleton() { }
    public static Singleton Instance
    {
        get
        {
            if (instance == null)
            {
                lock (lockObject)
                {
                    if (instance == null)
                        instance = new Singleton();
                }
            }
            return instance;
        }
    }
}

Related Topic