• Stars
    star
    122
  • Rank 292,031 (Top 6 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 2 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A concurrent, append-only vector.

boxcar

Crate Github Docs

A concurrent, append-only vector.

The vector provided by this crate suports concurrent get and push operations. All operations are lock-free.

Examples

Appending an element to a vector and retrieving it:

let vec = boxcar::Vec::new();
vec.push(42);
assert_eq!(vec[0], 42);

The vector can be shared across threads with an Arc:

use std::sync::Arc;

fn main() {
    let vec = Arc::new(boxcar::Vec::new());

    // spawn 6 threads that append to the vec
    let threads = (0..6)
        .map(|i| {
            let vec = vec.clone();

            std::thread::spawn(move || {
                vec.push(i); // push through `&Vec`
            })
        })
        .collect::<Vec<_>>();

    // wait for the threads to finish
    for thread in threads {
        thread.join().unwrap();
    }

    for i in 0..6 {
        assert!(vec.iter().any(|(_, &x)| x == i));
    }
}

Elements can be mutated through fine-grained locking:

use std::sync::{Mutex, Arc};

fn main() {
    let vec = Arc::new(boxcar::Vec::new());

    // insert an element
    vec.push(Mutex::new(1));

    let thread = std::thread::spawn({
        let vec = vec.clone();
        move || {
            // mutate through the mutex
            *vec[0].lock().unwrap() += 1;
        }
    });

    thread.join().unwrap();

    let x = vec[0].lock().unwrap();
    assert_eq!(*x, 2);
}

More Repositories

1

modern-unix

A collection of modern/faster/saner alternatives to common unix commands.
30,622
star
2

matchit

A high performance, zero-copy URL router.
Rust
342
star
3

papaya

A fast and ergonomic concurrent hash-table for read-heavy workloads.
Rust
341
star
4

seize

Fast, efficient, and robust memory reclamation for Rust.
Rust
340
star
5

astra

Rust web servers without async/await.
Rust
171
star
6

too-many-web-servers

https://ibraheem.ca/posts/too-many-web-servers/
Rust
98
star
7

awaitgroup

Wait for a collection of async tasks to finish.
Rust
32
star
8

dotfiles

My dotfiles for zsh, vim, i3, polybar, alacritty ...
Lua
23
star
9

httprouter-rs

A fast, minimal HTTP framework.
Rust
17
star
10

ripc

A C compiler, written in Rust.
Rust
9
star
11

firefly

High performance concurrent channels.
Rust
7
star
12

derive-alias

Alias mutliple derives as one.
Rust
7
star
13

mongo_beautiful_logger

A simple and beautiful logger gem for MongoDB in you Ruby/Rails app.
Ruby
6
star
14

jiffy

Rust implementation of the Jiffy MPSC queue.
Rust
4
star
15

platoon

A lightweight async runtime, for education purposes.
Rust
4
star
16

agilely

Agilely is an open source project management solution for individuals and teams alike.
Ruby
4
star
17

bison

A powerful web-application framework that does the heavy lifting for you.
Rust
2
star
18

ibraheemdev

Ibraheem Ahmed | Software developer. Open source enthusiast. Freelancer.
SCSS
1
star
19

turbofish

A fast, executor agnostic HTTP implementation in Rust.
Rust
1
star
20

go-chatrooms-example

This application shows how to use the websocket package to implement a simple web chat application with multiple rooms
Go
1
star
21

concurrent-dictionary

A port of C#'s ConcurrentDictionary to Rust.
Rust
1
star
22

papaya-db

Rust
1
star
23

dangerous-shell-commands

1
star