← ClaudeAtlas

principle-concurrencylisted

Concurrency principles — race conditions, deadlock, livelock, starvation, structured concurrency, cancellation propagation, backpressure, lock-free primitives, atomics, memory models, choosing between mutex vs channel vs actor vs semaphore vs CAS. Auto-load when designing concurrent code, debugging a race condition, fixing a deadlock, propagating cancellation, choosing a synchronization primitive, designing worker pools, or reasoning about goroutine/thread/task lifetimes.
lugassawan/swe-workbench · ★ 2 · Code & Development · score 68
Install: claude install-skill lugassawan/swe-workbench
# Concurrency Concurrency is a correctness hazard first, a performance tool second. Prove correctness before optimizing. ## Failure Modes **Race condition** — two goroutines/threads read and write shared state without synchronization; result is non-deterministic. **Fix:** mutex, channel, or atomic. **Deadlock** — two or more tasks each hold a lock the other needs; all block forever. **Fix:** consistent lock-acquisition ordering; prefer higher-level primitives. **Livelock** — tasks keep changing state in response to each other but make no progress; common in retry loops that back off identically. **Fix:** add jitter; use backpressure signals. **Starvation** — a low-priority task never gets scheduled because high-priority tasks monopolize a resource. **Fix:** fair queues; priority inheritance; rate limits. **Lost wakeup** — a condition-variable signal fires before the waiter starts waiting; waiter sleeps forever. **Fix:** always check the predicate in a loop; use atomic flags. **ABA problem** — a CAS succeeds because a value returned to A, masking an intervening change. **Fix:** use version tags or hazard pointers; prefer higher-level data structures. ## Structured Concurrency Child task lifetimes must nest inside the parent's lifetime. No orphan goroutines or threads. - When the parent exits, all children are cancelled first. - Errors propagate up — a child error surfaces to the parent, not to a background log line. - Never fire-and-forget unless the lifetime is expl