rust-concurrency

Guides Rust concurrency decisions across threads, async tasks, shared state, and channels.

3|Updated Aug 8, 2026
One-click install
npx skills add https://github.com/Jose-Polanco-Oxte/Echos-Live-Music-Visualizer --skill rust-concurrency-jose-polanco-oxte
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rust-concurrency
Source: https://github.com/Jose-Polanco-Oxte/Echos-Live-Music-Visualizer/tree/main/.agents/skills/rust/sub-skills/rust-concurrency
Command: npx skills add https://github.com/Jose-Polanco-Oxte/Echos-Live-Music-Visualizer --skill rust-concurrency-jose-polanco-oxte

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires tokio, tokio-util, rayon, parking_lot, dashmap.

What problem does it solve? Writing correct concurrent Rust code requires choosing between OS threads and async, picking the right sharing primitive, and resolving confusing compiler errors like "future is not Send" or deadlocks. This Skill provides decision frameworks and concrete fixes for these problems. ## Core Features & Use Cases - Threads vs Async Decisions: Match workload type (CPU-bound vs I/O-bound) to the right model, using rayon for data parallelism and tokio for high-concurrency I/O. - Sharing Model Guidance: Choose between channels, Arc, Mutex, RwLock, and atomics based on ownership and access patterns, including the actor pattern for state isolation. - Error Diagnosis: Map common errors (E0277 Send/Sync failures, future-not-Send, deadlocks, mutex poisoning) to concrete fixes such as dropping guards before await points. - Use Case: When a tokio task fails to compile with "future cannot be sent between threads safely" because an Rc is held across an await, this Skill explains the cause and shows the Arc-based or scoping fix. ## Quick Start Ask how to fix a "future is not Send" error in a tokio task that holds a value across an await point.

Frequently Asked Questions about rust-concurrency

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix "future is not Send" errors in tokio?

A future is not Send when a non-Send value like Rc or a std MutexGuard is held across an .await point. Replace Rc with Arc, drop the value before the await, or restructure so the non-Send value is created and dropped between awaits.

When should I use threads vs async in Rust?

Use OS threads or rayon for CPU-bound work like parsing and hashing, where real parallelism across cores matters. Use async with tokio for I/O-bound work with many concurrent connections, where cheap tasks outperform thread-per-connection.

Should I use Arc<Mutex<T>> or channels for shared state?

Prefer channels and message passing by default, since they turn data races into ownership transfers the compiler checks. Use Arc<Mutex<T>> only when data genuinely must be shared in place, or use the actor pattern where one task owns the state.

Why does my async Rust code deadlock with Mutex?

Deadlocks happen when a std MutexGuard is held across an .await, blocking the executor thread. Fix it by computing the value first, then locking briefly to store it, or use tokio::sync::Mutex only when the lock must span an await.

What is the difference between std Mutex and parking_lot Mutex?

parking_lot::Mutex is smaller, faster under low contention, and does not poison, so lock() returns the guard directly without unwrap. std locks have closed much of the performance gap, so switch only if profiling shows lock overhead.

How do I gracefully shut down tokio tasks?

Combine a CancellationToken to signal stop with a TaskTracker to wait for tasks to drain. Tasks select on token.cancelled() to exit their loops, then tracker.wait() ensures in-flight work finishes before the process exits.