Crate concurrent_queue

Source
Expand description

A concurrent multi-producer multi-consumer queue.

There are two kinds of queues:

  1. Bounded queue with limited capacity.
  2. Unbounded queue with unlimited capacity.

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 crate.

ยงExamples

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));

ยงFeatures

concurrent-queue uses an std default feature. With this feature enabled, this crate will use std::thread::yield_now to avoid busy waiting in tight loops. However, with this feature disabled, 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. See the 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 information.

Modulesยง

bounded ๐Ÿ”’
single ๐Ÿ”’
sync ๐Ÿ”’
Synchronization facade to choose between core primitives and loom primitives.
unbounded ๐Ÿ”’

Macrosยง

const_fn ๐Ÿ”’
Make the given function const if the given condition is true.

Structsยง

ConcurrentQueue
A concurrent queue.
ForcePushError
Error that occurs when force-pushing into a full queue.
TryIter
An iterator that pops items from a ConcurrentQueue.

Enumsยง

Inner ๐Ÿ”’
PopError
Error which occurs when popping from an empty queue.
PushError
Error which occurs when pushing into a full or closed queue.

Functionsยง

full_fence ๐Ÿ”’
Equivalent to atomic::fence(Ordering::SeqCst), but in some cases faster.