You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-52Lines changed: 37 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -101,6 +101,8 @@ A collection of minimal, self-contained C++ examples demonstrating multiple ways
101
101
* ⚠️ **Static Destruction Order Fiasco:**
102
102
* If a static object in another translation unit accesses the singleton during its own destruction, the singleton may already have been destroyed.
103
103
104
+
---
105
+
104
106
### 2️⃣ singleton-meyers-example
105
107
106
108
🔳 **Meyer's Singleton** → The simplest and safest modern C++ singleton implementation.
@@ -113,6 +115,8 @@ A collection of minimal, self-contained C++ examples demonstrating multiple ways
113
115
* ✅ **Fixes SIOF:** Avoids the classic static initialization order problem because the object is created on first use.
114
116
* ⚠️ **Still vulnerable to Static Destruction Order Fiasco**
115
117
118
+
---
119
+
116
120
### 3️⃣ singleton-classic-dynamic-example
117
121
118
122
🔳 **Singleton with a static member pointer** → Dynamically allocated on first use.
@@ -125,6 +129,7 @@ A collection of minimal, self-contained C++ examples demonstrating multiple ways
125
129
* ⚠️ **Manual lifetime management is error-prone**
126
130
* Because the singleton is destroyed explicitly via `delInstance()`, the program must ensure no code still uses the old instance after deletion.
127
131
132
+
---
128
133
129
134
### 4️⃣ singleton-cherno-example
130
135
@@ -137,6 +142,8 @@ A collection of minimal, self-contained C++ examples demonstrating multiple ways
137
142
* ⚠️ **Thread safety:** Not guaranteed, same as [singleton-classic-dynamic-example](#3️⃣-singleton-classic-dynamic-example)
138
143
* ⚠️ **Manual lifetime management is error-prone** → Same as [singleton-classic-dynamic-example](#3️⃣-singleton-classic-dynamic-example)
139
144
145
+
---
146
+
140
147
### 5️⃣ singleton-dclp-example
141
148
142
149
🔳 **Singleton with Double-Checked Locking Pattern (DCLP)** → Classic, but unsafe lazy-initialization pattern.
@@ -149,6 +156,8 @@ A collection of minimal, self-contained C++ examples demonstrating multiple ways
149
156
* ⛔ **Largely obsolete since C++11** → Thread-safe function-local static initialization is the simpler and preferred modern solution.
150
157
* 📖 **Reference:**[C++ and the Perils of Double-Checked Locking by Scott Meyers and Andrei Alexandrescu](https://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf)
151
158
159
+
---
160
+
152
161
### 6️⃣ singleton-leaky-example
153
162
154
163
🔳 **"Leaky" Singleton** → A heap-allocated singleton initialized through a function-local static pointer.
@@ -164,81 +173,55 @@ A collection of minimal, self-contained C++ examples demonstrating multiple ways
164
173
* Because the object is created on first use, it avoids SIOF
165
174
* Because it is never destroyed, it avoids static destruction order issues
166
175
* ⚠️ **Trade-off:** intentionally leaks memory by design
176
+
167
177
---
168
178
169
179
## ⚙️ Prerequisites
170
180
171
181
Before building, ensure you have the following installed:
172
182
173
-
### Common Requirements (All Platforms)
183
+
* CMake (v3.20 or newer required for Presets)
184
+
* C++ compiler supporting C++20 (required for `syncstream`)
174
185
175
-
***CMake** (v3.20 or newer required for Presets)
176
-
***Ninja** (Used on Linux and Windows (GCC))
186
+
#### 🖥️ Windows - Visual Studio MSVC (Preset: `windows-msvc`)
177
187
178
-
### 🖥️ Windows - Visual Studio MSVC (Preset: windows-msvc)
188
+
* Visual Studio 2022
189
+
* Workload Required: Desktop development with C++
190
+
* Note: The preset uses the Visual Studio 17 2022 generator.
179
191
180
-
***Visual Studio 2022**
181
-
***Workload Required: Desktop development with C++**
182
-
***Note: The preset uses the Visual Studio 17 2022 generator.**
192
+
#### 🖥️ Windows - MinGW (Preset: `windows-ninja-debug`)
183
193
184
-
### 🖥️ Windows - MinGW (Preset: windows-ninja-debug)
194
+
* MinGW-w64 Toolchain
195
+
* Generator: Ninja
185
196
186
-
***MinGW-w64 Toolchain**
187
-
***Generator: Ninja**
188
-
***Configuration: The bin folder of your MinGW installation (e.g., C:\msys64\mingw64\bin) must be in your system PATH environment variable.**
197
+
#### 🐧 Linux (Preset: `linux-ninja-debug`)
189
198
190
-
### 🐧 Linux (Preset: linux-ninja-debug)
199
+
* C++ Compiler (GCC/Clang)
200
+
* Generator: Ninja
191
201
192
-
***C++ Compiler: GCC 10+ or Clang 10+ (supporting C++20)**
0 commit comments