Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Design and review thread-based Rust concurrency with explicit ownership, sharing, and synchronization choices. Use when writing, refactoring, or reviewing threads, scoped threads, channels, Arc, Mutex, RwLock, Condvar, atomics, OnceLock, LazyLock, Send, Sync, deadlocks, or shared state.
.claude/skills/hashgraph-online-rust-concurrency-primitives/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-03 | ✗→✓ | ▲ Improved | 15% | 0% |
| case-12 | ✗→✓ | ▲ Improved | 25% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 10% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 2% | 0% |
| case-05 | ✓→✓ | = Same ✓ | 0% | 0% |
Use this skill to design thread-based Rust concurrency with explicit ownership, sharing, and synchronization. Prefer the simplest primitive that matches the coordination requirement before adding shared mutable state.
state, one-time initialization, or low-level atomic coordination.
observed or mutated by multiple threads.
std::thread::scope when child threads can borrow stack data and mustfinish before the function returns.
Arc<Mutex<T>> orArc<RwLock<T>> only when shared state is the clearer model.
holding a lock unless that is the invariant being protected.
OnceLock or LazyLock for thread-safe one-time initialization insteadof ad hoc global mutable state.
SeqCst by default until a weakerordering is justified and documented.
Read references/threading-shared-state.md before introducing a new shared state primitive or reviewing deadlock-prone code.
| Need | Primitive | |------|-----------| | Borrow local data into short-lived threads | std::thread::scope | | Transfer work or results | std::sync::mpsc or project channel crate | | Shared read/write state | Arc<Mutex<T>> | | Many readers, rare writers | Arc<RwLock<T>> | | Wait for condition changes | Condvar with Mutex | | One-time global initialization | LazyLock or OnceLock | | Counters, flags, lock-free coordination | std::sync::atomic |
Send for values crossing thread boundaries and Sync for sharedreferences used from multiple threads.
PoisonError::into_inner.
Arc::clone(&value) over value.clone() when the cloned value is anownership handle and readability matters.
parallelism and the project already accepts that dependency.
behavior when the code depends on it.
Other measured skills in the registry, with their headline benchmark lift.