A Rust implementation of various lock-free and concurrent data structures, demonstrating different synchronization patterns and mutual exclusion algorithms.
This project implements a comprehensive collection of concurrent data structures and synchronization primitives used in multi-threaded programming. Each module demonstrates different approaches to handling concurrent access to shared data—from traditional locks to lock-free algorithms.
clhlock.rs- Craig, Landin, and Hagersten (CLH) queue lock implementationmcslock.rs- MCS (Mellor-Crummey and Scott) queue lock implementationmcsparklock.rs- MCS parking lot lock variantticketlock.rs- Ticket lock (fairness-based mutual exclusion)prosem.rs- Parking lot-based semaphore implementation
lockfreelist.rs- Lock-free linked list using atomic operations and epoch-based memory reclamationtreiberstack.rs- Treiber's lock-free stack using compare-and-swap (CAS) operationsmsqueue.rs- Michael & Scott's lock-free queue
memord.rs- Memory ordering and synchronization primitiveslinearzibility.rs- Linearizability testing utilitiescrossbeam_example.rs- Examples using the crossbeam crate for epoch-based reclamationlocklink.rs- Lock-link utilities
These data structures use atomic operations and careful synchronization to avoid traditional locks:
- Compare-and-swap (CAS) operations
- Atomic references
- Epoch-based memory reclamation (via
crossbeam_epoch)
Traditional mutual exclusion algorithms that queue waiting threads:
- CLH Lock: Efficient for NUMA systems
- MCS Lock: Cache-friendly queue-based lock
- Ticket Lock: Simple, fair mutual exclusion
Proper memory ordering semantics for lock-free programming using Rust's std::sync::atomic module.
cargo buildcargo runThe main execution runs the lock-free list example by default. Modify main.rs to test different data structures.
- crossbeam - Provides epoch-based memory reclamation for safe lock-free structures
- std::sync::atomic - Atomic primitives for lock-free programming
This project focuses on concurrent algorithm implementation. For testing concurrent correctness:
cargo testThese implementations are useful for understanding:
- Multi-threaded synchronization techniques
- Lock-free algorithm design
- Memory safety in concurrent code
- Performance characteristics of different locking strategies
- All implementations are designed to be thread-safe (
SendandSynctraits properly implemented) - Memory reclamation is handled through epoch-based methods (crossbeam) to prevent use-after-free bugs
- Some structures use unsafe code for performance; safety is ensured through proper synchronization
Educational project for concurrent programming study