Thread-Unsafe Singleton
Overview
Lazy-initialized singletons without thread synchronization can result in multiple instances being created when the class is initialized concurrently by multiple threads. This causes inconsistent state, duplicate resource consumption, and potential security issues if security-related objects (loggers, auth managers) are duplicated.
Remediation
- Java: Use
enum,static initialization block, orsynchronized+volatile - Go: Use
sync.Once - Python: Use module-level variable (thread-safe by GIL) or
threading.Lock