Skip to content
Lock-free queues.
Rust
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
benches
examples
src
tests
.gitattributes
.gitignore
.travis.yml
CHANGELOG.md
Cargo.toml
LICENSE.txt
README.md

README.md

npnc

crates.io docs.rs Travis CI

Lock-free queues.

Supported on the stable, beta, and nightly Rust channels.

Released under the Apache License 2.0.

Features

  • Bounded lock-free SPSC queue
  • Bounded lock-free MPMC queue
  • Unbounded lock-free SPSC queue
  • Unbounded lock-free MPMC queue

Examples

Bounded SPSC

extern crate npnc;

use std::thread;

use npnc::bounded::spsc;

fn main() {
    let (producer, consumer) = spsc::channel(64);

    // Producer
    let b = thread::spawn(move || {
        for index in 0..32 {
            producer.produce(index).unwrap();
        }
    });

    // Consumer
    let a = thread::spawn(move || {
        loop {
            if let Ok(item) = consumer.consume() {
                println!("{}", item);
                if item == 31 {
                    break;
                }
            }
        }
    });

    a.join().unwrap();
    b.join().unwrap();
}
You can’t perform that action at this time.