synchonized? correct use? Thread-safe Singleton

BLS nanali at nospam-wanadoo.fr
Fri Jan 4 11:26:40 PST 2008


BLS schrieb:
> Do I have a THread-safe singleton ? If not HowTo..   Sorry. Sean K 
> allready explains it to me, but I 've lost the info. :(
> Bjoern
> 
> class Singleton(T)
> {
>   public:
>   static T instance()
>   sychronized       // according to the language spec this should work
>   {
>     if(_instance is null) _instance = new T;
>     return _instance;
>   }
> 
>   private:
>   this() {}
> 
>   static T _instance;
> }
> 
> class Application : Singleton!(Application)
> {
> }

Okay, I'll have to think more about this stuff.
In case that somebody can offer a templated (thread-safe and 
bulletproof) Singleton class. ... THANKS
Bjoern


More information about the Digitalmars-d-learn mailing list