orx-concurrent-queue
A high performance and convenient thread safe queue that can concurrently grow and shrink with push, extend, pop and pull capabilities.
Examples
The following example demonstrates a basic usage of ConcurrentQueue within a synchronous program. Note that push, extend, pop and pull methods can be called with a shared reference &self. This allows to use the queue conveniently in a concurrent program.
use ConcurrentQueue;
let queue = new;
queue.push; // [0]
queue.push; // [0, 1]
let x = queue.pop; // [1]
assert_eq!;
queue.extend; // [1, 2, 3, 4, 5, 6]
let x: = queue.pull.unwrap.collect; // [5, 6]
assert_eq!;
assert_eq!;
let vec = queue.into_inner;
assert_eq!;
The following example demonstrates the main purpose of the concurrent queue: to simultaneously push to and pop from the queue. This enables a parallel program where tasks can be handled by multiple threads, while at the same time, new tasks can be created and dynamically added to the queue.
In the following example, the queue is created with three pre-populated tasks. Every task might potentially lead to new tasks. These new tasks are also added to the back of the queue, to be popped later and potentially add new tasks to the queue.
use ConcurrentQueue;
use ;
let queue = new;
// pre-populate with 3 tasks
for micros in
// count total number of performed tasks
let num_performed_tasks = new;
let num_threads = 8;
scope;
assert_eq!;
Contributing
Contributions are welcome! If you notice an error, have a question or think something could be improved, please open an issue or create a PR.
License
Dual-licensed under Apache 2.0 or MIT.