# Thread-Unsafe Singleton Pattern

> Detects singleton implementations that are not thread-safe and can result in multiple instances being created under concurrent access.

- Skill: `zakirkun/thread-unsafe-singleton-pattern` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add zakirkun/thread-unsafe-singleton-pattern`
- Raw SKILL.md: https://api.skillmd.com/api/skills/zakirkun/thread-unsafe-singleton-pattern/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: zakirkun (https://skillmd.com/u/zakirkun)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/zakirkun/thread-unsafe-singleton-pattern

---


# 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`, or `synchronized` + `volatile`
- Go: Use `sync.Once`
- Python: Use module-level variable (thread-safe by GIL) or `threading.Lock`

