huiali/rust-skills/rust-concurrency
Claude Code and agent skill by huiali/rust-skills
- community
Checking that the SKILL.md file is still in the repository.
Concurrency and async programming expert. Handles Send, Sync, threads, async/await, tokio, channels, Mutex, RwLock, deadlock prevention, and race condition debugging.
Install
npx vskill@latest install huiali/rust-skills/rust-concurrencySKILL.md
Concurrency vs Async
| Dimension | Concurrency (threads) | Async (async/await) | |
|---|---|---|---|
| Memory | Each thread has separate stack | Single thread reused | |
| Blocking | Blocks OS thread | Doesn't block, yields | |
| Use case | CPU-intensive | I/O-intensive | |
| Complexity | Simple and direct | Requires runtime |
Key Insight: Threads for parallelism, async for concurrency.
Send/Sync Quick Reference
Send - Can Transfer Ownership Between Threads
Rule: If all fields are Send, the type is Send.
Sync - Can Share References Between Threads
Rule: &T is Send if T is Sync.
Solution Patterns
Pattern 1: Shared Mutable State
When to use: Multiple threads need to mutate shared data.
Trade-offs: Lock contention can limit scalability.
Pattern 2: Message Passing
When to use: Threads communicate without shared state.
Trade-offs: Copy/move overhead for messages.
Pattern 3: Async Runtime (Tokio)
When to use: I/O-bound operations (network, filesystem).
Trade-offs: Requires async runtime, function coloring.
Workflow
Step 1: Choose Concurrency Model
Step 2: Determine Data Sharing Strategy
Step 3: Verify Thread Safety
Common Errors & Solutions
| Error | Cause | Solution | |
|---|---|---|---|
| E0277 Send not satisfied | Contains non-Send types | Check all fields, replace Rc with Arc | |
| E0277 Sync not satisfied | Shared reference type not Sync | Wrap with Mutex/RwLock | |
| Deadlock | Inconsistent lock ordering | Establish and follow lock hierarchy | |
| MutexGuard across await | Lock held while suspended | Scope lock before await point | |
| Data race (runtime) | Improper synchronization | Use proper sync primitives |
Deadlock Prevention
Rule 1: Consistent Lock Ordering
Rule 2: Minimize Lock Scope
Rule 3: Avoid Locks Across Await
Performance Considerations
| Strategy | When to Use | Trade-offs | |
|---|---|---|---|
| Fine-grained locking | Lock small portions | More complex, avoid contention | |
| RwLock | Read-heavy workloads | Slower writes than Mutex | |
| Atomics | Simple counters/flags | Limited operations, no compound ops | |
| Message passing | Avoid shared state | Copy/move overhead | |
| Lock-free structures | High contention | Complex, use crates (crossbeam) |
Async-Specific Patterns
Spawning Tasks
Concurrent Operations
Timeout and Cancellation
Review Checklist
When reviewing concurrent code:
- [ ] All shared data properly synchronized (Arc/Mutex/RwLock)
- [ ] Send/Sync bounds satisfied for types crossing threads
- [ ] No locks held across await points
- [ ] Consistent lock ordering to prevent deadlocks
- [ ] Appropriate choice between threads and async
- [ ] Message passing channels used correctly (no deadlocks)
- [ ] Atomic operations used for simple shared state
- [ ] Thread pool sized appropriately for workload
- [ ] Error handling for lock poisoning
- [ ] Graceful shutdown and resource cleanup
Verification Commands
Common Pitfalls
1. Rc in Multi-threaded Context
Symptom: E0277 error, Rc<T> cannot be sent between threads
Fix: Replace Rc with Arc
2. Lock Across Await Points
Symptom: Deadlock or "future cannot be sent between threads safely"
Fix: Drop lock before await
3. Missing Arc Clone
Symptom: Borrow checker errors when spawning threads
Fix: Clone Arc before moving into closure
Related Skills
- rust-async - Advanced async patterns (Stream, select, backpressure)
- rust-async-pattern - Async architecture and design patterns
- rust-ownership - Understanding ownership for thread safety
- rust-mutability - Interior mutability patterns (Cell, RefCell)
- rust-performance - Concurrency performance optimization
- rust-unsafe - Writing safe concurrent abstractions
Localized Reference
- Chinese version: SKILL_ZH.md - 完整中文版本,包含所有内容
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
- semgrepPassed, 100 of 100
- njsscanPassed, 100 of 100
- trufflehogPassed, 100 of 100
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/rust-concurrency/SKILL.md
Popularity
- Repository stars
- 20
- Repository forks
- 4
- 7-day trend score
- 15
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 16 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/huiali/rust-skills/rust-concurrency)