#task #thread #executors #deterministic #real-time #lane #send

threadlanes

具有确定性任务路由和保证排序的实时执行器

1 个不稳定版本

使用旧的 Rust 2015

0.1.0 2022年2月1日

#4#executors

MIT/Apache

12KB
210

threadlanes

具有确定性任务路由和保证排序的实时执行器。

示例

用户定义的执行器

struct MyExecutor {
    id: usize,
}
impl LaneExecutor<usize> for MyExecutor {
    fn execute(&self, task: usize) {
       println!("{} received {}", self.id, task);
    }
}

使用 ThreadLanes

let lanes = ThreadLanes::new(vec![
    MyExecutor{id: 0},
    MyExecutor{id: 1},
    MyExecutor{id: 2},
]);

lanes.send(0, 11); // send task=11 to thread lane 0
lanes.send(1, 12); // send task=12 to thread lane 1
lanes.send(1, 13); // send task=13 to thread lane 1
lanes.send(2, 14); // send task=14 to thread lane 2
lanes.send(2, 15); // send task=15 to thread lane 2
lanes.send(2, 16); // send task=16 to thread lane 2

// flush tasks
lanes.flush();

在输出中,您会注意到每个执行器的任务顺序得到保留,但执行器之间的顺序没有保留

1 received 12
0 received 11
1 received 13
2 received 14
2 received 15
2 received 16

为什么选择 threadlanes

ThreadLanes 在您需要通过有状态的执行器进行确定性任务排序时很有用。这与线程池形成对比,在线程池中,执行任务的线程是不确定的。

依赖关系

~8KB