# Concurrency

> Use when: write or review concurrent code that avoids races, deadlocks, and shared-state bugs.

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

---


Goal: concurrent code that is correct first and fast second.

Use for:
- parallelizing work or handling many requests
- reviewing shared state, locking, and async flow
- diagnosing races, deadlocks, or corruption

Workflow:
1. Minimize shared mutable state; prefer message passing or immutability.
2. Define clear ownership of each mutable resource.
3. Protect shared state with the smallest necessary lock.
4. Acquire locks in a consistent order to avoid deadlock.
5. Set timeouts and cancellation on blocking operations.
6. Verify with stress tests and a race detector.

Patterns:
- immutable data shared freely without locks
- queues/channels to hand off work
- bounded concurrency to limit resource use
- idempotent operations for safe retries

Rules:
- share by communicating, or protect shared state explicitly
- keep critical sections tiny
- a consistent lock order prevents deadlocks
- never assume ordering; test under contention

