concurrency-correctness
Skill20 starsChanged 4 months agoMITView on GitHub
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 atomic operations with explicit memory orders (std::memory_order_*, atomic.LoadAcquire, Ordering::Relaxed), implements lazy initialization with double-checked locking, or calls a blocking operation (I/O, sleep, await, blocking channel send) inside a locked region.
In this repository52 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- authentication-failuresSkill
- broken-access-controlSkill
- contract-reviewSkill
- cryptographic-failuresSkill
- crypto-library-misuseSkill
- csrfSkill
- exceptional-conditionsSkill
- excessive-agencySkill
- file-uploadSkill
- graphql-securitySkill
- hardcoded-secretsSkill
- header-injectionSkill
- hotspotsSkill
- injectionSkill
- insecure-designSkill
- insecure-local-storageSkill
- insecure-output-handlingSkill
- insecure-plugin-designSkill
- integrity-failuresSkill
- ipc-securitySkill
- llm-supply-chainSkill
- logging-failuresSkill
- mass-assignmentSkill
- mcp-securitySkill
- memory-api-misuseSkill
- model-dosSkill
- model-theftSkill
- multi-agent-trustSkill
- nosql-injectionSkill
- numeric-trust-boundarySkill
- oauth-implementationSkill
- open-redirectSkill
- overrelianceSkill
- path-traversalSkill
- privilege-handlingSkill
- prompt-injectionSkill
- prototype-pollutionSkill
- pr-reviewSkill
- race-conditionSkill
- rag-securitySkill
- redosSkill
- security-cleanupSkill
- security-misconfigurationSkill
- security-reviewSkill
- sensitive-disclosureSkill
- ssrfSkill
- supply-chainSkill
- threat-modelSkill
- token-smugglingSkill
- training-data-poisoningSkill
- unsafe-api-consumptionSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 34
Lock order is canonical and total: Every code path that acquires two or more locks acquires them in the same sequence — sorted by address, …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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
- Lock held across a blocking operation —
await,sleep, blocking I/O, or a blocking channel send — so every other waiter blocks on the slow thing - Inconsistent lock order across call sites — one path acquires
(L1, L2), another acquires(L2, L1), producing classic AB-BA deadlock - Recursive acquisition of a non-recursive mutex on the same thread
- Atomic flag published with relaxed ordering where acquire/release is required — the reader can observe the flag set before the writer's payload writes are visible
- Double-checked locking where the outer read of the published pointer or flag uses no acquire barrier
- Acquiring a lock and then sending on an unbuffered channel whose receiver needs the same lock to make progress
- Async cancellation that interrupts a critical section without restoring invariants
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.
- No blocking operation inside a held lock. Snapshot whatever state is needed under the lock, release the lock, then perform the I/O,
await, orsleepon the snapshot. The critical section stays bounded by CPU work only. - 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.
- 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.
- 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.
- 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.
- No
await, sleep, blocking I/O, or blocking channel send appears inside a held-lock scope - When a function acquires two or more locks, the order is total — every code path that holds both acquires them in the same sequence
- Every relaxed-ordered atomic operation is paired with a comment explaining why relaxed is sufficient (e.g. statistics counter, not a synchronization flag)
- Lazy initialization uses a once-helper, a thread-safe function-local static, or an atomic with explicit acquire/release on both reads — not hand-rolled double-checked locking without a barrier
- No recursive lock attempt on a non-recursive mutex
References
- CWE-833 (Deadlock)
- CWE-820 (Missing Synchronization)
- CWE-667 (Improper Locking)
- CWE-362 (Race Condition)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

