Singleton
Ensure a class has only one instance and provide a global point of access to it.
The Problem
Some resources must have exactly one instance — a log sink, a device handle, a thread pool. Global variables work but offer no lazy initialization, thread safety, or controlled destruction. Multiple instances of a Logger would interleave output; multiple thread pools would thrash the scheduler.
Structure
Execution Walkthrough
Private ctor
Constructor is private — no external code can call new Logger(). Prevents accidental duplication.
Static instance
instance() call
Delete copies
Use anywhere
Code Comparison
Full C++ Implementation
Participants
Where it is used
Thread pools
A global worker pool constructed once at startup — all subsystems submit tasks to the same pool.
Logging systems
Valgrind's log sink, production loggers like spdlog's default logger — one sink, all writers.
Hardware drivers
A GPU device handle is initialized once — reopening the device for every subsystem would fail or leak.
Config registry
Parsed YAML config loaded once at boot — every module reads from the same registry without file I/O.