switchyard
所属分类:其他
开发工具:Rust
文件大小:0KB
下载次数:0
上传日期:2023-05-24 12:59:03
上 传 者:
sh-1993
说明: 具有作业池、线程本地数据和优先级的实时以计算为中心的异步执行器。,
(Real-time compute-focused async executor with job pools, thread-local data , and priorities.,)
文件列表:
switchyard-trunk/ (0, 2023-08-25)
switchyard-trunk/.rustfmt.toml (111, 2023-08-25)
switchyard-trunk/CHANGELOG.md (1380, 2023-08-25)
switchyard-trunk/Cargo.toml (810, 2023-08-25)
switchyard-trunk/LICENSE.APACHE (11347, 2023-08-25)
switchyard-trunk/LICENSE.MIT (1074, 2023-08-25)
switchyard-trunk/LICENSE.ZLIB (861, 2023-08-25)
switchyard-trunk/benches/ (0, 2023-08-25)
switchyard-trunk/benches/scheduling.rs (3473, 2023-08-25)
switchyard-trunk/deny.toml (459, 2023-08-25)
switchyard-trunk/src/ (0, 2023-08-25)
switchyard-trunk/src/affinity.rs (464, 2023-08-25)
switchyard-trunk/src/error.rs (700, 2023-08-25)
switchyard-trunk/src/lib.rs (21479, 2023-08-25)
switchyard-trunk/src/task.rs (10582, 2023-08-25)
switchyard-trunk/src/threads.rs (2738, 2023-08-25)
switchyard-trunk/src/util.rs (1093, 2023-08-25)
switchyard-trunk/src/worker.rs (4962, 2023-08-25)
switchyard-trunk/tests/ (0, 2023-08-25)
switchyard-trunk/tests/interface.rs (374, 2023-08-25)
switchyard-trunk/tests/panic.rs (1243, 2023-08-25)
switchyard-trunk/tests/simple.rs (4956, 2023-08-25)
switchyard-trunk/tests/threads.rs (539, 2023-08-25)
switchyard-trunk/tests/ub.rs (1815, 2023-08-25)
# switchyard
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/BVE-Reborn/switchyard/CI)
[![Crates.io](https://img.shields.io/crates/v/switchyard)](https://crates.io/crates/switchyard)
[![Documentation](https://docs.rs/switchyard/badge.svg)](https://docs.rs/switchyard)
![License](https://img.shields.io/crates/l/switchyard)
Real-time compute-focused async executor with job pools, thread-local data, and priorities.
## Example
```rust
use switchyard::Switchyard;
use switchyard::threads::{thread_info, one_to_one};
// Create a new switchyard without thread local data
let yard = Switchyard::new(one_to_one(thread_info(), Some("thread-name")), ||()).unwrap();
// Spawn a task on priority 10 and get a JoinHandle
let handle = yard.spawn(10, async move { 5 + 5 });
// Spawn a lower priority task
let handle2 = yard.spawn(0, async move { 2 + 2 });
// Wait on the results
assert_eq!(handle.await + handle2.await, 14);
```
## How Switchyard is Different
Switchyard is different from other existing async executors, focusing on situations where
precise control of threads and execution order is needed. One such situation is using
task parallelism to parallelize a compute workload.
### Priorites
Each task has a priority and tasks are ran in order from high priority to low priority.
```rust
// Spawn task with lowest priority.
yard.spawn(0, async move { /* ... */ });
// Spawn task with higher priority. If both tasks are waiting, this one will run first.
yard.spawn(10, async move { /* ... */ });
```
### Thread Local Data
Each yard has some thread local data that can be accessed using [`spawn_local`](Switchyard::spawn_local).
Both the thread local data and the future generated by the async function passed to [`spawn_local`](Switchyard::spawn_local)
may be `!Send` and `!Sync`. The future will only be resumed on the thread that created it.
If the data is `Send`, then you can call [`access_per_thread_data`](Switchyard::access_per_thread_data) to get
a vector of mutable references to all thread's data. See it's documentation for more information.
```rust
// Create yard with thread local data. The data is !Sync.
let yard = Switchyard::new(one_to_one(thread_info(), Some("thread-name")), || Cell::new(42)).unwrap();
// Spawn task that uses thread local data. Each running thread will get their own copy.
yard.spawn_local(0, |data| async move { data.set(10) });
```
## MSRV
1.51
Future MSRV bumps will be breaking changes.
License: MIT OR Apache-2.0 OR Zlib
近期下载者:
相关文件:
收藏者: