The singleton design pattern force to have only one instance of a class.
The implementation require a mechanism to access the same instance of the class without recreate it every time. It can be achieved creating a class with a method that creates a new instance of the class if one does not exist. If an instance already exists, it simply returns a reference to that object. To make sure that the object cannot be instantiated any other way, the constructor is made protected.

In multi-thread application however, two thread may be able to execute the creation method at the same time when a singleton does not yet exist and obtain two different instance of the class.
To avoid this situation, you must allow a single thread to enter the critical area of code:
class Singleton
{
private static Singleton _instance;
private static object sync = new Object();
protected Singleton() {}
public static Singleton GetInstance()
{
if (_instance == null)
{
// ensures that only one thread enter in
// critical section of code
lock (sync)
{
if (_instance == null)
_instance = new Singleton();
}
}
return _instance;
}
}
4404a275-07d4-43b5-857f-eb4f4cc095b0|0|.0