#parallel #systems #resources #ecs

shred

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

31 releases

✓ Uses Rust 2018 edition

0.9.3 Sep 9, 2019
0.9.2 Jun 28, 2019
0.8.1 May 24, 2019
0.7.1 Oct 28, 2018
0.4.3 Jun 21, 2017

#8 in Concurrency

Download history 1002/week @ 2019-05-27 803/week @ 2019-06-03 1309/week @ 2019-06-10 979/week @ 2019-06-17 1196/week @ 2019-06-24 1231/week @ 2019-07-01 1224/week @ 2019-07-08 948/week @ 2019-07-15 1233/week @ 2019-07-22 1176/week @ 2019-07-29 1534/week @ 2019-08-05 1187/week @ 2019-08-12 1158/week @ 2019-08-19 1441/week @ 2019-08-26 1833/week @ 2019-09-02

5,442 downloads per month
Used in 99 crates (19 directly)

MIT/Apache

155KB
3K 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, ResourceId, System, SystemData, World, Write};

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

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

#[derive(SystemData)] // Provided with `shred-derive` feature
struct Data<'a> {
    a: Read<'a, ResA>,
    b: Write<'a, ResB>,
}

struct EmptySystem;

impl<'a> System<'a> for EmptySystem {
    type SystemData = Data<'a>;

    fn run(&mut self, bundle: Data<'a>) {
        println!("{:?}", &*bundle.a);
        println!("{:?}", &*bundle.b);
    }
}

fn main() {
    let mut world = World::empty();
    let mut dispatcher = DispatcherBuilder::new()
        .with(EmptySystem, "empty", &[])
        .build();
    world.insert(ResA);
    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

~1.5–2.1MB
~43K SLoC