📦 Blazingly Fast Concurrent Data Structures
- 🪪 Thread-safe with spin-lock backoff and kernel-level mutexes
- ⚡ Optimized for high-concurrency workloads
- 💾 Optimized cloning with safe memory management via internal reference counting
- 🔐 Internal mutability
✨ AtomicVec
AtomicVec is a high-performance, thread-safe vector supporting concurrent push and pop operations with minimal locking overhead. It uses block-based allocation, atomic indices, and internal backoff strategies to manage memory efficiently in multi-threaded contexts.
- 🧠 Suitable for implementing queues, stacks, and other dynamic collections
- 🛡️ Shared/exclusive locking for safe access and reset operations
- ♻️ Automatic block recycling and free-list management
- 📦 Can convert to standard Vec safely, consuming elements
Example
use thread;
use AtomicVec;
let h = new;
h.push;
let b = h.clone;
drop;
assert!;
✨ AtomicHashMap
AtomicHashMap a blazingly fast thread-safe, concurrent hash map that supports high-performance insertion, retrieval, and removal of key-value pairs.
It uses fine-grained atomic operations combined with internal mutexes to manage contention efficiently.
- 🧠 Ideal for shared caches, state maps, and in high concurrency scenario
- 📏 It uses resizable bucket array to optimize hash distribution and performance
Example
use thread;
use AtomicHashMap;
let h = new;
h.insert;
let b = h.clone;
drop;
assert_eq!;
✨ AtomicBuffer
AtomicBuffer is a lock-free, bounded, and thread-safe ring buffer.
It provides atomic push and pop operations without requiring locks, making it ideal for high-performance concurrent producer/consumer systems.
- 🧠 Suitable for work queues, message passing, or object pooling systems
Example
use AtomicBuffer;
use thread;
let buffer = with_capacity;
let producer = ;
let consumer = ;
producer.join.unwrap;
consumer.join.unwrap;
✨ AtomicCell
AtomicCell is a thread-safe, lock-assisted atomic container that provides interior mutability with cloneable reference counting.
It combines mutex-protected access, raw memory management, and atomic reference counting to safely store and manipulate a single value in concurrent environments.
- 🧠 Ideal for shared single-value state in multithreaded programs
Example
use thread;
use AtomicCell;
let c = new;
let c2 = c.clone;
let handle = spawn;
handle.join.unwrap;
assert_eq!;
✨ AtomicArray
AtomicArray is a lock-assisted, thread-safe array optimized for concurrent reads and writes.
It combines atomic indices, per-slot locks, and cache-friendly memory layout to provide efficient and safe access in multi-threaded environments.
- 🧠 Optimized for high-concurrency workloads with backoff spins
Example
use thread;
use AtomicArray;
let arr = with_capacity;
let arr_clone = arr.clone;
let t = spawn;
t.join.unwrap;
arr.for_each_mut;
assert_eq!;
✨ Atomic — Universal Atomic Wrapper
Atomic is a powerful generic atomic type providing thread-safe access to any Rust type T.
It supports complex types, structs, enums, collections, primitives, and user-defined data — all synchronized via an internal SMutex.
- 🧠 Works with any type: primitives, structs, enums, strings, vectors, and custom types
- 🔄 Provides atomic load, store, swap, update, and compare-exchange operations
- 🧩 Specialized methods for common containers (
Vec<T>,String,Option<T>) - 🧮 Supports numeric and bitwise atomic operations (
fetch_add,fetch_sub, etc.) - 🔐 Thread-safe interior mutability with minimal overhead
Example
use Atomic;
use Arc;
use thread;
let atomic = new;
let atomic2 = atomic.clone;
let handle = spawn;
handle.join.unwrap;
let result = atomic.load;
assert_eq!;
assert_eq!;
✨ RwLock
RwLock is a lightweight, synchronization primitive for safe concurrent access. It provides multi-reader / single-writer locking with minimal kernel interaction.
- ⚡ Fast atomic + futex-based design
- 🔒 Shared (read) and exclusive (write) modes
- 🧩 Clonable via internal ref-count (no data copy)
- ✅ Compared to std::RwLock: user-space (faster, no poisoning, clonable).
Example
use RwLock;
use thread;
use sleep;
use Duration;
let mutex = new;
let m1 = mutex.clone;
let h1 = spawn;
let m2 = mutex.clone;
let h2 = spawn;
h1.join.unwrap;
h2.join.unwrap;
✨ Barrier — Thread Synchronization Primitive
Barrier is a lightweight, thread-safe synchronization primitive that coordinates groups of threads.
It blocks threads until a specified number of waiters arrive, then releases them all simultaneously.
Once released, the barrier resets to a configurable capacity for reuse.
- 🧠 Suitable for parallel algorithms, phased execution, and workload synchronization
Example
use Barrier;
use thread;
let barrier = with_capacity;
let mut handles = vec!;
for _ in 0..3
for h in handles
📦 Installation
Install crossync from crates.io
Open your Cargo.toml and add:
[]
= "0.0.2" # or the latest version available
📄 License
Apache-2.0