concurrency-safety
Skill486 starsChanged 15 days agoApache-2.0View on GitHub
Concurrency safety patterns for R3BL - Chain of Custody, Loud Lock Releases, and Ergonomic Atomics. Use when working with threads, locks, or atomics.
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 5 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 13
When designing thread-safe modules like Reactor, Monitor, or Engine.
- Very specific: line 14
When refactoring state management to use AtomicU8Ext.
- Distinctive: line 15
When troubleshooting deadlocks or race conditions.
- Distinctive: line 26
Recursion Detection: Use recursion detection (Safety-First) to prevent terminal-hanging deadlocks.
- Distinctive: line 28
Fail-Fast vs. Poison-Safe: Use Fail-Fast (panic) for normal logic, but Poison-Safe (recover) for cleanup paths to avoid Double Panic Aborts.
- Distinctive: line 38
Avoid "Stale Guards" by ensuring the guard is either consumed or explicitly dropped.
- Very specific: line 46
Explicit Release: Always call drop(guard) immediately when a critical section ends, especially before function returns, macro calls, or …
- Distinctive: line 48
No Implicit Drops: Do not rely on scope-based implicit drops for complex logic or when calling into external code/macros.
- Very specific: line 56
Type-Safe Subscriptions: Use specific enums (like SubscriptionStrategy) instead of generic types to map thread states to execution paths at …
- Very specific: line 57
Ergonomic Atomics: Always use AtomicU8Ext (e.g., get(), set(), increment()) instead of raw load()/store() with manual Ordering.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 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 Safety Skill
Apply these principles to ensure thread safety, prevent deadlocks, and maintain high-performance, predictable execution in multi-threaded code.
When to Use
- Proactively when working with
Mutex,RwLock,Atomic, orCondvar. - When designing thread-safe modules like
Reactor,Monitor, orEngine. - When refactoring state management to use
AtomicU8Ext. - When troubleshooting deadlocks or race conditions.
Core Principles
1. Scoped Access (Deadlock Prevention)
For simple shared state, use closure-based access to structurally prevent deadlocks by making it impossible to hold a lock guard longer than necessary.
Guidelines:
- Closure-Based Access: Restrict state access to closures. The closure's scope is the lock's scope.
- Recursion Detection: Use recursion detection (Safety-First) to prevent terminal-hanging deadlocks. Panic with a clear message if a recursive lock is detected.
- Performance Opt-out: For hot paths, opt-out of recursion detection at compile-time for zero overhead.
- Fail-Fast vs. Poison-Safe: Use Fail-Fast (panic) for normal logic, but Poison-Safe (recover) for cleanup paths to avoid Double Panic Aborts.
2. Chain of Custody (Guard Passing)
For complex state machines requiring Condvar, ensure linear ownership of locks by passing and returning MutexGuard by value.
Guidelines:
- Pass
MutexGuardas a parameter to internal helper functions to guarantee they operate within an existing critical section. - Return
MutexGuardfrom state-reading closures (e.g.,read_state) to force the caller to be intentional about the lock's lifetime. - Avoid "Stale Guards" by ensuring the guard is either consumed or explicitly dropped.
3. Loud Lock Releases
Make critical section boundaries explicit and easy to audit by using drop(guard).
Guidelines:
- Explicit Release: Always call
drop(guard)immediately when a critical section ends, especially before function returns, macro calls, or long-running operations. - Auditability: Explicit drops make it clear to reviewers (and the compiler) exactly where a lock is held, preventing accidental deadlocks during refactoring.
- No Implicit Drops: Do not rely on scope-based implicit drops for complex logic or when calling into external code/macros.
4. Friction as a Feature (Ergonomic API Design)
Design APIs that make it harder to mismanage concurrency.
Guidelines:
- Type-Safe Subscriptions: Use specific enums (like
SubscriptionStrategy) instead of generic types to map thread states to execution paths at compile time. - Ergonomic Atomics: Always use
AtomicU8Ext(e.g.,get(),set(),increment()) instead of rawload()/store()with manualOrdering.
5. Visibility for Documentation
Balance encapsulation with discoverability for documentation.
Guidelines:
- Make internal fields
pubif they are targets of public documentation links. - Rely on the "Barrel Export" pattern (
mod.rsre-exports) to maintain actual module-level encapsulation while allowingcargo docto resolve links correctly.
Supporting Files
patterns.md- Good and Bad examples of concurrency safety patterns.
Related Skills
design-philosophy- Core principles (Cognitive Load, Progressive Disclosure).check-code-quality- Includes concurrency safety in its final checklist.
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- MANVENDRA-github/agentry★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository30 other files it gives its agents.
- .agents/AGENTS.mdAGENTS.md
- AGENTS.mdAGENTS.md
- build-infra/AGENTS.mdAGENTS.md
- rust-analyzer-mcp-server/AGENTS.mdAGENTS.md
- task/AGENTS.mdAGENTS.md
- llms.txtllms.txt
- analyze-log-filesSkill
- analyze-performanceSkill
- audit-taskSkill
- batch-refactor-with-sub-agentsSkill
- check-bounds-safetySkill
- check-code-qualitySkill
- check-test-coverageSkill
- code-reviewSkill
- create-commit-messageSkill
- create-prSkill
- design-philosophySkill
- fast-string-allocationsSkill
- fix-issueSkill
- merge-prSkill
- organize-modulesSkill
- organize-testsSkill
- release-crateSkill
- remove-crate-prefixSkill
- review-prSkill
- run-clippySkill
- safe-renamingSkill
- test-cross-platformSkill
- write-documentationSkill
- write-structured-tracingSkill
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.

