#parallel #systems #resources #ecs

shred

Dispatches systems in parallel which need read access to some resources, and write access to others

26 releases

✓ Uses Rust 2018 edition

new 0.8.0 Apr 18, 2019
0.7.1 Oct 28, 2018
0.7.0 May 13, 2018
0.6.2 Mar 6, 2018
0.4.3 Jun 21, 2017

#10 in Concurrency

Download history 855/week @ 2019-01-04 627/week @ 2019-01-11 805/week @ 2019-01-18 804/week @ 2019-01-25 672/week @ 2019-02-01 649/week @ 2019-02-08 893/week @ 2019-02-15 514/week @ 2019-02-22 854/week @ 2019-03-01 596/week @ 2019-03-08 474/week @ 2019-03-15 602/week @ 2019-03-22 687/week @ 2019-03-29 744/week @ 2019-04-05 1467/week @ 2019-04-12

3,185 downloads per month
Used in 55 crates (16 directly)

MIT/Apache

114KB
2.5K SLoC

shred - Shared resource dispatcher

Build Status Crates.io MIT/Apache Docs.rs LoC

This library allows to dispatch systems, which can have interdependencies, shared and exclusive resource access, in parallel.

Usage

extern crate shred;

use shred::{DispatcherBuilder, Read, Resource, System, World, Write};

#[derive(Debug, Default)]
struct ResA;

#[derive(Debug, Default)]
struct ResB;

struct PrintSystem;

// Systems should be generic over the
// context if possible, so it's easy
// to introduce one.
impl<'a> System<'a> for PrintSystem {
    type SystemData = (Read<'a, ResA>, Write<'a, ResB>);

    fn run(&mut self, data: Self::SystemData) {
        let (a, mut b) = data;

        println!("{:?}", &*a);
        println!("{:?}", &*b);

        *b = ResB; // We can mutate ResB here
        // because it's `FetchMut`.
    }
}

fn main() {
    let mut world = World::new();
    let mut dispatcher = DispatcherBuilder::new()
        .with(PrintSystem, "print", &[]) // Adds a system "print" without dependencies
        .build();
    //world.add(ResA); (We don't need to add `ResA`, a default value will be instantiated)
    world.insert(ResB);

    dispatcher.dispatch(&mut world);
}

Please see the benchmark for a bigger (and useful) example.

Required Rust version

1.32 stable

Features

  • lock-free
  • no channels or similar functionality used (-> less overhead)
  • allows both automated parallelization and fine-grained control

Contribution

Contribution is highly welcome! If you'd like another feature, just create an issue. You can also help out if you want to; just pick a "help wanted" issue. If you need any help, feel free to ask!

All contributions are assumed to be dual-licensed under MIT/Apache-2.

License

shred is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT.

Dependencies

~666KB
~13K SLoC