# Atomicity Violation

> Detects code sequences that must be atomic but are not protected by synchronization, allowing interleaving that violates invariants.

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

---


# Atomicity Violation

## Overview
Atomicity violations occur when a sequence of operations that must execute as a unit can be interleaved by other threads. Unlike simple counter races, these involve multi-step operations where the intermediate state is invalid.

Example: Check-then-act on user balance, file existence, or session state.

## Remediation
- Wrap multi-step operations in mutex/lock
- Use database transactions for multi-step data operations
- Use compare-and-swap (CAS) operations for lock-free atomic sequences

