rust-concurrency

pluginagentmarketplace's avatarfrom pluginagentmarketplace

Master Rust concurrency - threads, channels, and parallel iterators

⭐1stars🔀0forks📁View on GitHub🕐Updated Jan 5, 2026

When & Why to Use This Skill

This Claude skill empowers developers to master Rust concurrency by providing expert guidance on threads, channels, synchronization primitives, and parallel processing. It simplifies complex concepts like data races and deadlocks, offering production-ready code snippets for building high-performance, thread-safe applications using both the Rust standard library and the Rayon framework.

Use Cases

  • Case 1: Implementing high-performance multi-threaded data processing using std::thread and Arc/Mutex for safe shared state.
  • Case 2: Designing robust inter-thread communication systems using MPSC channels to prevent data races.
  • Case 3: Scaling CPU-bound tasks across multiple cores using parallel iterators and the Rayon library for maximum efficiency.
  • Case 4: Optimizing read-heavy workloads with RwLock and atomic operations to minimize synchronization overhead.
  • Case 5: Troubleshooting and resolving common concurrency issues like deadlocks and slow parallel execution in Rust projects.
namerust-concurrency
descriptionMaster Rust concurrency - threads, channels, and parallel iterators
sasmp_version"1.3.0"
bonded_agentrust-async-agent
bond_typeSECONDARY_BOND
version"1.0.0"

Rust Concurrency Skill

Master thread-based concurrency: threads, channels, synchronization, and parallel processing.

Quick Start

Threads

use std::thread;

let handle = thread::spawn(|| {
    println!("Hello from thread!");
    42
});

let result = handle.join().unwrap();

Channels

use std::sync::mpsc;

let (tx, rx) = mpsc::channel();

thread::spawn(move || {
    tx.send("message").unwrap();
});

println!("Got: {}", rx.recv().unwrap());

Mutex

use std::sync::{Arc, Mutex};

let counter = Arc::new(Mutex::new(0));
let mut handles = vec![];

for _ in 0..10 {
    let counter = Arc::clone(&counter);
    handles.push(thread::spawn(move || {
        *counter.lock().unwrap() += 1;
    }));
}

for h in handles { h.join().unwrap(); }

Parallel Iterators (Rayon)

use rayon::prelude::*;

let sum: i32 = (0..1000)
    .into_par_iter()
    .map(|x| x * 2)
    .sum();

Parallel Operations

// Parallel map
let results: Vec<_> = data.par_iter()
    .map(|x| expensive(x))
    .collect();

// Parallel sort
data.par_sort();

Synchronization

RwLock

use std::sync::RwLock;

let data = RwLock::new(vec![]);

// Multiple readers
let read = data.read().unwrap();

// Single writer
let mut write = data.write().unwrap();

Atomics

use std::sync::atomic::{AtomicUsize, Ordering};

let counter = AtomicUsize::new(0);
counter.fetch_add(1, Ordering::SeqCst);

Troubleshooting

Problem Solution
Deadlock Lock in same order
Data race Use Arc<Mutex>
Slow parallel Increase work per thread

Resources