Giter VIP home page Giter VIP logo

nolock's Introduction

Docs Crates.io

Nolock

A collection of Lock-Free (sometimes also Wait-Free) algorithms and datastructures

Goal

The Goal of this Crate is to provide a save, easy to use and fast implementation for a variety of different Lock-Free or Wait-Free datastructures.

no_std Support

Rust's no_std is supported for parts of this crate, to use this you need to disable the default features of the Crate and can then enable the specific features you need. Currently supported are:

  • queues

Feature-Flags

Name Default Description
std true Enables the std, which is needed for most of the other Features
queues true Enables the different Queues implementation
hash_trie true Enables the Hash-Trie-Map implementation
async true Enables async varients of different Datastructures
thread_data true Enables the lockfree Thread-Local-Storage
hazard_ptr true Enables the Hazard-Pointer implementation
hyaline true Enables the Hyaline implementation
full true Enables all Feature-Flags

Development

Benchmarking

  • Running benchmarks using cargo bench --bench criterion_bench --
  • Running benchmarks with profiling using cargo bench --bench criterion_bench -- --profile-time=5

nolock's People

Contributors

lol3rrr avatar

Stargazers

 avatar  avatar Ycy avatar José Luis Cruz avatar Hunter Beast avatar  avatar Luis Hebendanz avatar Christoph Grabo avatar

Watchers

James Cloos avatar  avatar

nolock's Issues

Occationally panic on jiffy mpsc node

I wrote a demo with the jiffy mpsc module on Win10. Mostly it wen well but I came across once with panic info:

thread '' panicked at 'called Option::unwrap() on a None value', C:\Users\testuser.cargo\registry\src\mirrors.ustc.edu.cn-15f9db60536bad60\nolock-0.4.0\src\queues\mpsc\jiffy\node.rs:93:25
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

I read the function comments and found that the unwrap() function is meant to be safe. Would there be any bug in it?

My test code is below:

use std::thread;
use std::time::{Duration, Instant};
use core_affinity::{CoreId, get_core_ids};
use polars::prelude::{DataFrame, NamedFromOwned, Series};

fn main() {
    loop {
        let (mut receiver, mut sender) = nolock::queues::mpsc::jiffy::queue::<Instant>();
        let times = 10000;
        let times_clone = times.clone();

        let receiver = thread::spawn(move || {
            core_affinity::set_for_current(CoreId { id: 3 });
            let mut num = 0;
            let mut sum_latency = 0.0;
            let mut latencies = vec![];
            for idx in 0..times_clone {
                if let Some(info) = receiver.dequeue() {
                    let a = info.elapsed().as_secs_f64();
                    latencies.push(a);
                }
            }
            let series = Series::from_vec("", latencies);
            let df = DataFrame::new(vec![series]).unwrap();
            println!("{:?}", df.describe(None));
        });

        thread::spawn(move || {
            core_affinity::set_for_current(CoreId { id: 4 });
            for idx in 0..times {
                thread::sleep(Duration::from_millis(1));
                let start = Instant::now();
                sender.enqueue(start);
            }
        });
        receiver.join();
    }
}

Use Const-Generics on Bounded Queues

Idea

Using Const-Generics to specify the Size of bounded Queues.

Benefits

This would allow us to use Arrays instead of Vecs, which is good as well as encoding the Size of the Queue somewhere else. The Fact that we would use Arrays with a known size might also allow the compiler to remove more bounds checks but that has not been tested.

Problems

The Fact that the size of the Queues would be encoded in the Type itself, means that callers must specify the Size of the Queue as well or also have a const generic on them for the size. This could very quickly infect a lot of the Code-Base if they are used very frequently or in key places.

Alternative

Use const generics for internal Queues that are sometimes used as Part of building other (often unbounded) Queues, this could still give a nice performance improvement in some cases (more testing required).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.