• Stars
    star
    100
  • Rank 330,021 (Top 7 %)
  • Language
    Rust
  • License
    MIT License
  • Created about 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.
29,534
star
2

matchit

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

seize

Fast, efficient, and robust memory reclamation for Rust.
Rust
299
star
4

astra

Rust web servers without async/await.
Rust
161
star
5

too-many-web-servers

https://ibraheem.ca/posts/too-many-web-servers/
Rust
80
star
6

awaitgroup

Wait for a collection of async tasks to finish.
Rust
28
star
7

dotfiles

My dotfiles for zsh, vim, i3, polybar, alacritty ...
Lua
24
star
8

httprouter-rs

A fast, minimal HTTP framework.
Rust
16
star
9

ripc

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

firefly

High performance concurrent channels.
Rust
6
star
11

derive-alias

Alias mutliple derives as one.
Rust
6
star
12

jiffy

Rust
4
star
13

platoon

A lightweight async runtime for Rust.
Rust
4
star
14

mongo_beautiful_logger

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

agilely

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

bison

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

ibraheemdev

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

turbofish

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

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
20

seize-hashmap

A Rust concurrent HashMap optimized for read-heavy workloads.
Rust
1
star
21

tictactoe

A react powered tictactoe app
JavaScript
1
star
22

papaya-db

Rust
1
star
23

dangerous-shell-commands

1
star