Jump to content

Singleton: Difference between revisions

(Add Perl 6 example.)
Line 271:
// And any other protected methods.
}</lang>
 
=={{header|C#}}==
<lang C#>
Thread save singleton implementation.
To make it non thread safe remove lockObject and the lock() statement
 
// Usage: Singleton.Instance.SomeMethod()
class Singleton
{
private static Singleton _singleton;
private static lockObject = new object();
private Singleton() {}
public static Singleton Instance
{
get
{
lock(lockObject)
{
if (_singleton == null)
_singleton = new Singleton();
}
return _settings;
}
}
// The rest of the methods
}
</lang>
 
=={{header|Erlang}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.