<<< Singleton Collaboration with Clients | Index | Singleton Sample >>> |
If instance of the class does not exist, the new instance is created.
If an instance already exists, Singleton simply returns a reference to that object.
(Singleton constructor must be protected or private to make sure that the object cannot be instantiated in any other way.)
The singleton pattern must be carefully constructed in multi-threaded applications:
If two threads execute the creation method at the same time. When a singleton instance does not yet exist, both threads must
check if instance exists
only one of the threads should create the new instance.
In concurrent processing, the Singleton::GetInstance( ) should be implemented as a mutually exclusive operation.
<<< Singleton Collaboration with Clients | Index | Singleton Sample >>> |