| Crates.io | simple-channels |
| lib.rs | simple-channels |
| version | 0.1.2 |
| created_at | 2025-07-11 14:42:55.519834+00 |
| updated_at | 2025-07-11 15:12:52.383115+00 |
| description | A simple, educational implementation of channels in Rust. |
| homepage | |
| repository | https://github.com/johvnik/simple-channels |
| max_upload_size | |
| id | 1748019 |
| size | 44,690 |
A collection of simple, thread-safe channel implementations in Rust, created for educational purposes. This project focuses on demonstrating the core principles of concurrent data structures using clear, concise code.
The initial implementation is a Multi-Producer, Single-Consumer (MPSC) channel.
Lock-Free RingBuf: A fixed-size, circular buffer that uses atomic operations and a compare-and-swap (CAS) loop to manage concurrent access without mutexes.
MPSC Channel API: A high-level Sender/Receiver API built on the RingBuf.
Sender can be cloned to allow writes from multiple threads.Receiver consumes values, enforcing the single-consumer model.The implementation prioritizes clarity and fundamental concepts over raw performance.
Blocking Strategy: The channel uses a simple spin-and-yield approach (std::thread::yield_now()) for blocking. When the buffer is full or empty, threads yield their execution slot, avoiding more complex synchronization primitives like park/unpark.
State Management: Shared channel state is managed via Arc, and disconnection is detected by checking the atomic reference count.
This project can be extended by implementing other common channel types and features. Potential future work includes:
std::thread::park to reduce CPU usage while waiting.