Concurrency correctness

From thejefflarson/soundcheck · View interactive version

Concurrency correctness is an AI agent skill from the GitHub repository thejefflarson/soundcheck. Detects multi-threaded code where a lock is held across a blocking operation, lock acquisition order risks deadlock, lock-free atomics use the wrong memory ordering, or double-checked locking is missing the necessary barrier. Use when writing or modifying code that acquires multiple locks, uses atom

How to use this skill

Skill file

Concurrency Correctness (CWE-833, CWE-820, CWE-667)

What this checks

Concurrency bugs that read clean in isolation but produce deadlocks, lost wakeups, or

data races in production. Race detectors catch triggered races but not structural

mistakes. Flags local patterns: lock-around-blocking-call, lock-order in nested

acquires, atomic memory order, double-checked locking. Not a replacement for

whole-program ownership analysis (borrow checker, lockdep, model checking).

Vulnerable patterns

Fix immediately

Flag the vulnerable code, explain the risk, and suggest a fix establishing these

properties. Translate to the concurrency primitives of the audited file — use that

language's documented lock, atomic, once-cell, and channel APIs; do not import a recipe

from a different language.

  1. No blocking operation inside a held lock. Snapshot whatever state is needed under the lock, release the lock, then perform the I/O, await, or sleep on the snapshot. The critical section stays bounded by CPU work only.
  2. Lock order is canonical and total. Every code path that acquires two or more locks acquires them in the same sequence — sorted by address, by name, or via a scoped/multi-lock primitive that handles ordering. Document the ordering rule near the lock declarations.
  3. Memory ordering on atomics matches the synchronization need. Use acquire on the read and release on the write whenever an atomic publishes a pointer, flag, or sequence that the reader will then dereference. Relaxed ordering is reserved for counters and statistics where no other state depends on the value.
  4. Lazy initialization uses a primitive that is correct by construction — a one-shot init helper, a function-local static where the language guarantees thread-safe initialization, or an atomic with explicit acquire/release on both the outer and inner reads. Hand-rolled double-checked locking without a barrier is not acceptable.
  5. Non-recursive mutexes are never re-entered on the same thread. When a recursive call site genuinely needs to take the lock again, use the recursive variant explicitly.

Verification

Criteria apply only to constructs the audited file actually contains;

mark inapplicable bullets N/A rather than skipping silently.

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.