m07-concurrency
CRITICAL: Use for concurrency/async. Triggers: E0277 Send Sync, cannot be sent between threads, thread, spawn, channel, mpsc, Mutex, RwLock, Atomic, async, await, Future, tokio, deadlock, race condition, 并发, 线程, 异步, 死锁
Security Assessment
About m07-concurrency
This skill is the concurrency and async reference (module m07, "Layer 1: Language Mechanics") from the actionbook "rust-skills" collection. It addresses a recurring source of confusion in Rust: Send/Sync trait errors, deadlocks, and the choice between threads and async. Its core framing is to ask whether a workload is CPU-bound or I/O-bound and what the data-sharing model is, so that concurrency primitives are chosen deliberately rather than by trial-and-error against compiler errors like E0277.
The SKILL.md supplies error-to-design-question tables, a mandatory "trace up" step that detects the surrounding domain (web, fintech, cloud-native, CLI) to surface domain constraints, and "trace down" guidance mapping needs to primitives: `std::thread`/`rayon` for CPU work, `tokio`/async for I/O, `Arc<T>` for shared immutable data, `Arc<Mutex<T>>` or `Arc<RwLock<T>>` for shared mutable state, and channels for message passing. Supporting files include async patterns (task spawning, select, mpsc/oneshot/broadcast/watch channels, structured concurrency with JoinSet, cancellation tokens, graceful shutdown, and backpressure with bounded channels and semaphores), common concurrency errors, thread patterns, and a comparison document.
The audience is intermediate-to-advanced Rust developers building concurrent or async systems who want to resolve Send/Sync problems at the design level and pick correct synchronization primitives. Use cases include diagnosing "cannot be sent between threads" errors, choosing between mutexes and channels, structuring tokio task groups, and implementing cancellation and backpressure. Like its sibling modules it carries bilingual (English/Chinese) trigger phrases.
FAQ
What problem does this skill target?
Choosing correct concurrency and async primitives in Rust and resolving Send/Sync (E0277) trait errors and deadlocks at the design level instead of patching them ad hoc.
Does it cover async runtimes like tokio?
Yes. The async patterns file covers tokio task spawning, select!, mpsc/oneshot/broadcast/watch channels, JoinSet, cancellation tokens, graceful shutdown, and backpressure.
How does it help decide between threads and async?
It routes CPU-bound work to std::thread or rayon and I/O-bound work to async/await, with a hybrid spawn_blocking path for mixed workloads.
Is this runnable tooling or documentation?
It is documentation: reference tables, decision flowcharts, and annotated code examples. It does not execute code on your system.
Who is it for?
Intermediate-to-advanced Rust developers working on concurrent or async code who want principled guidance rather than quick error suppressions.
Install m07-concurrency
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
actionbook/rust-skills