$ show crossbeam-rs/crossbeam
Crossbeam is a Rust library workspace providing a comprehensive set of concurrent programming primitives. It includes multi-producer multi-consumer (MPMC) channels with a select! macro for multiplexing, work-stealing deques (Chase-Lev), lock-free queues (bounded ArrayQueue and unbounded SegQueue), epoch-based memory reclamation for safe lock-free memory management, lock-free skip lists (SkipMap/SkipSet), and utilities like cache-padded values, exponential backoff, thread parking, sharded locks, and scoped threads. The library is designed for building high-performance concurrent systems and supports no_std environments. The architecture is modular: each major component lives in its own crate (crossbeam-channel, crossbeam-deque, crossbeam-epoch, crossbeam-queue, crossbeam-skiplist, crossbeam-utils) with a root umbrella crate that re-exports them. The implementations are based on academic literature (Chase-Lev, Michael-Scott, Vyukov queues) and include extensive testing with Miri, Loom model checking, and sanitizers. The codebase demonstrates advanced Rust patterns: unsafe but carefully encapsulated atomic operations, macro_rules-based DSLs, and trait-based abstraction for selectable channels. While primarily a library, the repository also contains benchmarks and examples that serve as both documentation and performance validation. The project is actively maintained with a clear MSRV policy and regular releases. Some components, like the epoch GC and work-stealing deque, are self-contained patterns that could be extracted for use in other concurrent Rust projects.
The LLM identified 5 files worth highlighting for reuse:
Implements epoch-based memory reclamation for concurrent data structures. Provides a Collector that manages global epochs, thread-local bags, and deferred destruction of retired objects. The pattern allows safe deallocation in lock-free algorithms without immediate garbage collection. Reusable as a standalone memory management scheme for any concurrent Rust project.
Implements the Chase-Lev work-stealing deque with Worker, Stealer, and Injector roles. Supports FIFO and LIFO modes, batched stealing, and dynamic circular buffer resizing. A classic concurrent data structure useful for task schedulers and load balancing. The implementation is careful about memory ordering and uses atomic operations for correctness.
Provides the select! and select_biased! macros for multiplexing over multiple channel operations. Uses Rust's macro_rules to implement a state machine that parses channel expressions, validates cases at compile time, and generates efficient polling code. Demonstrates advanced declarative macro programming with compile-time diagnostics.
Implements exponential backoff with three phases: spin, yield, and park. Used throughout the codebase to reduce contention in spin loops. The Backoff struct provides snooze() and reset() methods and is parameterizable. A small, self-contained utility that can be extracted into any concurrent Rust project.
Provides CachePadded<T> wrapper that ensures a value is aligned to a cache line (typically 64 or 128 bytes) to prevent false sharing. Guarantees that the pointer to the CachePadded equals the pointer to the inner T. A simple but essential utility for concurrent systems programming.