#parallel #systems #resources #ecs

shred

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

38 releases

0.12.0 Jun 7, 2021
0.11.1 Mar 16, 2021
0.11.0 Dec 21, 2020
0.10.2 Feb 12, 2020
0.4.3 Jun 21, 2017

#122 in Concurrency

Download history 1409/week @ 2021-07-02 1941/week @ 2021-07-09 1721/week @ 2021-07-16 1624/week @ 2021-07-23 1696/week @ 2021-07-30 2234/week @ 2021-08-06 1245/week @ 2021-08-13 1773/week @ 2021-08-20 907/week @ 2021-08-27 785/week @ 2021-09-03 1940/week @ 2021-09-10 1426/week @ 2021-09-17 715/week @ 2021-09-24 689/week @ 2021-10-01 973/week @ 2021-10-08 969/week @ 2021-10-15

5,720 downloads per month
Used in less than 13 crates

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.38 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.4MB
~50K SLoC