Skip to content

Commit de97c30

Browse files
authored
Update README.md
1 parent 6345a35 commit de97c30

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

CreationalPatterns/Singleton/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
## Static Initialization
66

7-
:thumbsup: **You may want to create your Singleton eagerly, if**
7+
:thumbsup: **You may want to create your Singleton eagerly**, if
88
* your application always creates and uses an instance of the `Singleton`
99
* the overhead of creation and runtime aspects of the Singleton are not onerous
1010

11-
[ChocolateBoiler_StaticInit.cs](CreationalPatterns/Singleton/ChocolateBoiler_StaticInit.cs).
11+
:thumbsdown: **Downside**
12+
* You have less control over the mechanics of the instantiation
13+
14+
[ChocolateBoiler_StaticInit.cs](/CreationalPatterns/Singleton/ChocolateBoiler_StaticInit.cs).
1215
```cs
1316
public sealed class ChocolateBoiler_StaticInit
1417
{
@@ -29,8 +32,11 @@ The class is marked as **sealed** to prevent derivation, which could add instanc
2932

3033
Because the **Singleton** instance is referenced by a private static member variable, the instantiation does not occur until the class is first referenced by a call to the **Instance** property. This solution therefore implements a form of the lazy instantiation property, as in the Design Patterns form of Singleton.
3134

32-
:thumbsdown: **Downside**
33-
* You have less control over the mechanics of the instantiation
35+
## Multithreaded Singleton
36+
37+
:thumbsup: **Use double-checked locking**, if
38+
* you want to keep separate threads from creating new instances of the singleton at the same time (thread-safe)
39+
* you want to create an instance only when the instance is needed.
3440

3541
Reference:
3642
* MSDN - [Implementing Singleton in C#](https://msdn.microsoft.com/en-us/library/ff650316.aspx)

0 commit comments

Comments
 (0)