# Double-Checked Locking Anti-Pattern

> Detects broken double-checked locking implementations that create race conditions in singleton initialization.

- Skill: `zakirkun/double-checked-locking-anti-pattern` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add zakirkun/double-checked-locking-anti-pattern`
- Raw SKILL.md: https://api.skillmd.com/api/skills/zakirkun/double-checked-locking-anti-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/double-checked-locking-anti-pattern

---


# Double-Checked Locking Race Condition

## Overview
Double-checked locking is a common but often incorrectly implemented pattern for lazy singleton initialization. Without proper memory ordering or volatile declarations, the second check can observe a partially-initialized object due to instruction reordering.

In Java pre-5.0 (without `volatile`), this is broken. In Go, use `sync.Once` instead.

## Remediation
- Java: Declare singleton field `volatile`
- Go: Use `sync.Once` for lazy initialization
- C++: Use `std::call_once` or `std::atomic`

