--- a/Singleton.st Wed Apr 03 08:33:16 2019 +0200
+++ b/Singleton.st Wed Apr 03 08:37:30 2019 +0200
@@ -99,6 +99,49 @@
]
].
^ theOnlyInstance.
+!
+
+new
+ "allocate a singleton in a thread-safe way.
+ Do lazy locking here"
+
+ theOnlyInstance isNil ifTrue:[
+ Lock critical:[
+ theOnlyInstance isNil ifTrue:[
+ theOnlyInstance := super basicNew initialize.
+ ].
+ ]
+ ].
+ ^ theOnlyInstance.
+
+ "Created: / 01-04-2019 / 12:05:25 / Stefan Vogel"
+!
+
+new:count
+ "allocate a singleton in a thread-safe way.
+ Do lazy locking here"
+
+ theOnlyInstance isNil ifTrue:[
+ Lock critical:[
+ theOnlyInstance isNil ifTrue:[
+ theOnlyInstance := (super basicNew:count) initialize.
+ ].
+ ]
+ ].
+ ^ theOnlyInstance.
+
+ "Created: / 01-04-2019 / 12:05:42 / Stefan Vogel"
+!
+
+releaseInstance
+ "release the singleton's instance.
+ Use only for debugging!!"
+
+ Lock critical:[
+ theOnlyInstance := nil.
+ ].
+
+ "Created: / 01-04-2019 / 12:02:58 / Stefan Vogel"
! !
!Singleton class methodsFor:'accessing'!