crossbeam

repository·main·Indexed 27 days ago

https://github.com/crossbeam-rs/crossbeam

A collection of tools for concurrent programming in Rust, providing high-performance primitives for atomics, data structures, memory management, and thread synchronization. It includes specialized subcrates such as crossbeam-channel for MPMC channels, crossbeam-deque for work-stealing deques, crossbeam-epoch for epoch-based garbage collection, crossbeam-queue for concurrent queues, crossbeam-skiplist for concurrent maps and sets, and crossbeam-utils for synchronization primitives and scoped threads.

Tokens
22.4K
Snippets
67
Records
142
Agent score
93%

What's inside crossbeam

  1. Overview of Crossbeam Epoch

    main
    Crossbeam Epoch provides epoch-based garbage collection (GC) designed for building concurrent data structures. It solves the problem of safe memory reclamation: when a thread removes an object from a concurrent structure, other threads might still hold pointers to it. This crate provides an efficient mechanism to defer the destruction of shared objects until it is guaranteed that no pointers to them exist.
  2. Overview of crossbeam-channel features

    main

    crossbeam-channel provides high-performance message passing with the following capabilities:

    • MPMC Support: Both Senders and Receivers can be cloned and shared among multiple threads.
    • Channel Types:
      • bounded: Channels with a fixed capacity.
      • unbounded: Channels with no fixed capacity.
    • Specialized Channels:
      • after: Provides a timer-based channel.
      • never: A channel that can never receive a message.
      • tick: Provides a periodic timer channel.
    • Selection Mechanisms:
      • select! macro: Allows blocking on multiple channel operations simultaneously.
      • Select struct: Allows selecting over a dynamically built list of channel operations.
  3. Overview of crossbeam-utils features

    main

    Atomics

    • AtomicCell: A thread-safe mutable memory location. (no_std)
    • AtomicConsume: For reading from primitive atomic types with "consume" ordering. (no_std)

    Thread synchronization

    • Parker: A thread parking primitive.
    • ShardedLock: A sharded reader-writer lock with fast concurrent reads.
    • WaitGroup: For synchronizing the beginning or end of some computation.

    Utilities

    • Backoff: For exponential backoff in spin loops. (no_std)
    • CachePadded: For padding and aligning a value to the length of a cache line. (no_std)
    • scope: For spawning threads that borrow local variables from the stack.
  4. Overview of Crossbeam tools

    main

    Crossbeam provides a suite of tools for concurrent programming, categorized by functionality:

    Atomics

    • AtomicCell: A thread-safe mutable memory location (supports no_std).
    • AtomicConsume: For reading from primitive atomic types with "consume" ordering (supports no_std).

    Data structures

    • deque: Work-stealing deques for building task schedulers.
    • ArrayQueue: A bounded MPMC (multi-producer multi-consumer) queue with a fixed-capacity buffer (requires alloc).
    • SegQueue: An unbounded MPMC queue that allocates small buffers (segments) on demand (requires alloc).

    Memory management

    • epoch: An epoch-based garbage collector (requires alloc).

    Thread synchronization

    • channel: MPMC channels for message passing.
    • Parker: A thread parking primitive.
    • ShardedLock: A sharded reader-writer lock optimized for fast concurrent reads.
    • WaitGroup: Synchronizes the beginning or end of computations.

    Utilities

    • Backoff: Exponential backoff for spin loops (supports no_std).
    • CachePadded: Pads and aligns values to the length of a cache line (supports no_std).
    • scope: Spawns threads that can safely borrow local variables from the stack.
  5. Use ArrayQueue and SegQueue for concurrent queues

    main

    The crossbeam-queue crate provides two types of Multi-Producer Multi-Consumer (MPMC) queues:

    • ArrayQueue: A bounded queue that allocates a fixed-capacity buffer upon construction.
    • SegQueue: An unbounded queue that allocates small buffers (segments) on demand.

    Both types can be used in no_std environments if the alloc feature is enabled.