Atomicity Violation

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

zakirkun 72d476b 2 files · 2.0 KB Updated

File contents

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

zakirkun/ice-tea/tree/main/skills/race-condition/atomicity-violation commit 72d476b735

Frequently asked questions

npx skillmds@latest add zakirkun/atomicity-violation