Skip to content

Commit 1c0651f

Browse files
committed
Update README.md
1 parent fb8dc01 commit 1c0651f

1 file changed

Lines changed: 37 additions & 52 deletions

File tree

README.md

Lines changed: 37 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ A collection of minimal, self-contained C++ examples demonstrating multiple ways
101101
* ⚠️ **Static Destruction Order Fiasco:**
102102
* If a static object in another translation unit accesses the singleton during its own destruction, the singleton may already have been destroyed.
103103

104+
---
105+
104106
### 2️⃣ singleton-meyers-example
105107

106108
🔳 **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
113115
***Fixes SIOF:** Avoids the classic static initialization order problem because the object is created on first use.
114116
* ⚠️ **Still vulnerable to Static Destruction Order Fiasco**
115117

118+
---
119+
116120
### 3️⃣ singleton-classic-dynamic-example
117121

118122
🔳 **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
125129
* ⚠️ **Manual lifetime management is error-prone**
126130
* Because the singleton is destroyed explicitly via `delInstance()`, the program must ensure no code still uses the old instance after deletion.
127131

132+
---
128133

129134
### 4️⃣ singleton-cherno-example
130135

@@ -137,6 +142,8 @@ A collection of minimal, self-contained C++ examples demonstrating multiple ways
137142
* ⚠️ **Thread safety:** Not guaranteed, same as [singleton-classic-dynamic-example](#3️⃣-singleton-classic-dynamic-example)
138143
* ⚠️ **Manual lifetime management is error-prone** → Same as [singleton-classic-dynamic-example](#3️⃣-singleton-classic-dynamic-example)
139144

145+
---
146+
140147
### 5️⃣ singleton-dclp-example
141148

142149
🔳 **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
149156
***Largely obsolete since C++11** → Thread-safe function-local static initialization is the simpler and preferred modern solution.
150157
* 📖 **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)
151158

159+
---
160+
152161
### 6️⃣ singleton-leaky-example
153162

154163
🔳 **"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
164173
* Because the object is created on first use, it avoids SIOF
165174
* Because it is never destroyed, it avoids static destruction order issues
166175
* ⚠️ **Trade-off:** intentionally leaks memory by design
176+
167177
---
168178

169179
## ⚙️ Prerequisites
170180

171181
Before building, ensure you have the following installed:
172182

173-
### Common Requirements (All Platforms)
183+
* CMake (v3.20 or newer required for Presets)
184+
* C++ compiler supporting C++20 (required for `syncstream`)
174185

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`)
177187

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.
179191

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`)
183193

184-
### 🖥️ Windows - MinGW (Preset: windows-ninja-debug)
194+
* MinGW-w64 Toolchain
195+
* Generator: Ninja
185196

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`)
189198

190-
### 🐧 Linux (Preset: linux-ninja-debug)
199+
* C++ Compiler (GCC/Clang)
200+
* Generator: Ninja
191201

192-
* **C++ Compiler: GCC 10+ or Clang 10+ (supporting C++20)**
193-
* **Generator: Ninja**
194-
* **Install Command (Ubuntu/Debian):** ```bash sudo apt update && sudo apt install build-essential ninja-build cmake ```
195-
* **Note:** GCC 10+ is available by default on Ubuntu 22.04+. On older distros, install via `sudo apt install gcc-10 g++-10`.
202+
---
196203

197204
## 🏗️ Build Instructions
198205

199206
The commands below are executed from the **root of the repository**.
200207

201-
### 1. Configure Workspace (Run Once)
202-
203-
#### 🖥️ Windows (MSVC)
204-
205-
```bash
206-
cmake --preset windows-msvc
207-
```
208-
209-
#### 🖥️ Windows (MinGW - Debug)
208+
#### 1. Configure Workspace (run once)
210209

211-
```bash
212-
cmake --preset windows-ninja-debug
213-
```
210+
* 🖥️ Windows (MSVC) → `cmake --preset windows-msvc`
214211

215-
#### 🐧 Linux (Ninja - Debug)
212+
* 🖥️ Windows (MinGW) → `cmake --preset windows-ninja-debug`
216213

217-
```bash
218-
cmake --preset linux-ninja-debug
219-
```
214+
* 🐧 Linux → `cmake --preset linux-ninja-debug`
220215

221-
### Build All (Debug)
216+
#### Build All (debug)
222217

223-
#### 🖥️ Windows (MSVC)
218+
* 🖥️ Windows (MSVC)`cmake --build --preset windows-msvc-debug`
224219

225-
```bash
226-
cmake --build --preset windows-msvc-debug
227-
```
220+
* 🖥️ Windows (MinGW - Debug) → `cmake --build --preset windows-ninja-debug`
228221

229-
#### 🖥️ Windows (MinGW - Debug)
222+
* 🐧 Linux (Ninja - Debug)`cmake --build --preset linux-ninja-debug`
230223

231-
```bash
232-
cmake --build --preset windows-ninja-debug
233-
```
234-
235-
#### 🐧 Linux (Ninja - Debug)
236-
237-
```bash
238-
cmake --build --preset linux-ninja-debug
239-
```
240-
241-
### Build Specific Project
224+
#### Build Specific Project
242225

243226
```bash
244227
cmake --build --preset <preset> --target <target_name>
@@ -249,20 +232,22 @@ Example:
249232
cmake --build --preset linux-ninja-debug --target 02-singleton-meyers-example
250233
```
251234

235+
---
236+
252237
## 🏃 Running Examples
253238

254-
### 🖥️ Windows (MSVC)
239+
#### 🖥️ Windows (MSVC)
255240
```bash
256241
build/windows-msvc/singleton-meyers-example/Debug/02-singleton-meyers-example.exe
257242
```
258243

259-
### 🖥️ Windows (MinGW)
244+
#### 🖥️ Windows (MinGW)
260245
```bash
261246
build/windows-ninja-debug/singleton-meyers-example/02-singleton-meyers-example.exe
262247
```
263248

264249

265-
### 🐧 Linux
250+
#### 🐧 Linux
266251
```bash
267252
./build/linux-ninja-debug/singleton-meyers-example/02-singleton-meyers-example
268253
```

0 commit comments

Comments
 (0)