Guides Rust concurrency and async design decisions, from Send/Sync errors to choosing threads, channels, or async runtimes.
- What it does
- This skill is a reference for reasoning about Rust concurrency and async programming. It maps common compiler errors such as E0277 Send/Sync and non-Send futures to underlying design questions, and provides decision tables for choosing between threads, async/await, channels, Arc, Mutex, RwLock, and atomics. It also lists anti-patterns and async-specific pitfalls like holding a MutexGuard across an await.
- When to use it
- Use it when working through Rust concurrency or async problems, especially Send/Sync trait errors, deadlocks, race conditions, or decisions about threads versus async. It is also useful when choosing a sharing model for data accessed across threads or tasks.
- Requirements
- No scripts or runtime dependencies; it is an instructions-only reference document. It assumes familiarity with Rust concurrency concepts and may reference related skills such as domain-web, domain-cli, m09-domain, and m10-performance.
Concurrency
Layer 1: Language Mechanics
Core Question
Is this CPU-bound or I/O-bound, and what's the sharing model?
Before choosing concurrency primitives:
- What's the workload type?
- What data needs to be shared?
- What's the thread safety requirement?
Error → Design Question
Thinking Prompt
Before adding concurrency:
-
What's the workload?
- CPU-bound → threads (std::thread, rayon)
- I/O-bound → async (tokio, async-std)
- Mixed → hybrid approach
-
What's the sharing model?
- No sharing → message passing (channels)
- Immutable sharing → Arc<T>
- Mutable sharing → Arc<Mutex<T>> or Arc<RwLock<T>>
-
What are the Send/Sync requirements?
- Cross-thread ownership → Send
- Cross-thread references → Sync
- Single-thread async → spawn_local
Trace Up ↑ (MANDATORY)
CRITICAL: Don't just fix the error. Trace UP to find domain constraints.
Domain Detection Table
Example: Web API + Rc Error
Generic Trace
Trace Down ↓
From design to implementation:
Send/Sync Markers
Quick Reference
Decision Flowchart
Common Errors
Anti-Patterns
Async-Specific Patterns
Avoid MutexGuard Across Await
Non-Send Types in Async
Related Skills