Concurrency

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

kimtth 67bba2e 1.0 KB Updated

File contents

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

kimtth/agent-skill-100-lines-or-less/tree/main/skills/concurrency commit 67bba2eb27

Frequently asked questions

npx skillmds@latest add kimtth/concurrency