A concurrent multi-producer multi-consumer queue.
There are two kinds of queues:
Queues also have the capability to get closed at any point. When closed, no more items can be pushed into the queue, although the remaining items can still be popped.
These features make it easy to build channels similar to
std::sync::mpsc on top of this
use concurrent_queue::ConcurrentQueue; let q = ConcurrentQueue::unbounded(); q.push(1).unwrap(); q.push(2).unwrap(); assert_eq!(q.pop(), Ok(1)); assert_eq!(q.pop(), Ok(2));
concurrent-queue uses an
std default feature. With this feature enabled, this crate will
std::thread::yield_now to avoid busy waiting in tight loops. However, with this
core::hint::spin_loop will be used instead. Disabling
std will allow
this crate to be used on
no_std platforms at the potential expense of more busy waiting.
There is also a
portable-atomic feature, which uses a polyfill from the
portable-atomic crate to provide atomic operations on platforms that do not support them.
README for the
portable-atomic crate for more information on how to use it.
Note that even with this feature enabled,
concurrent-queue still requires a global allocator
to be available. See the documentation for the
std::alloc::GlobalAlloc trait for more
- A concurrent queue.
- Error which occurs when popping from an empty queue.
- Error which occurs when pushing into a full or closed queue.