Working with Asynchrony Generically: A Tour of C++ Executors
extern unifex::static_thread_pool low_latency; extern unifex::static_thread_pool workers; unifex::taskaccept_and_process_requests() { while (true) { auto request = co_await ex::on(low_latency { ex::set_done((R&&) r_); } };42 SENDERS AND COROUTINES43 // This is a coroutine: unifex::task read_socket_async(socket, span ); int main() { socket s = /*...*/; char buff[1024]; in a coroutine type trivially. // This is a coroutine: unifex::task read_socket_async(socket, span ); unifex::task concurrent_read_async(socket s1, socket s2) { char buff1[1024]; 0 码力 | 121 页 | 7.73 MB | 5 月前3Rust 异步并发框架在移动端的应用 - 陈明煜
Syntax sugar wake await Rust 异步机制 Asynchronous Rust Rust 异步机制 Asynchronous Rust Waker Task Future task Queue wake Worker Future.poll() Reactor fd fd listen listen find 现有并发框架 Third Party 多线程模型提供了并行迭代器功能, 适用于处理 CPU 密集型计算任务 rayon 现有框架无法完美适配移动端(一) Core Thread Thread Worker Worker task task Local queue Local queue Tokio 采用了如右图这种 GMP 模式: • 一核可以绑定多线程,每个线程拥有一个 Worker ,每个 Worker 拥有一个任务队列 Mobile spawn_blocking 调度模式 spawn 调度模式 Thread Worker task Local queue Thread Thread task Global queue task New task Global queue New task take & run take & run Worker take & run Steal & run0 码力 | 25 页 | 1.64 MB | 1 年前3CeresDB Rust 生产实践 任春韶
生产实践 – Async lock runtime.spawn(task0) runtime.spawn(task1) runtime.spawn(task2) 生产实践 – Async lock runtime.spawn(task0) runtime.spawn(task1) runtime.spawn(task2) 生产实践 – Async lock 总结: Async spawn(task0) runtime.spawn(task1) runtime.spawn(task2) runtime.spawn(task3) 生产实践 – Mixed workload cpu_runtime.spawn(task0) cpu_runtime.spawn(task1) cpu_runtime.spawn(task2) cpu_runtime.spawn(task3)0 码力 | 22 页 | 6.95 MB | 1 年前3Await-Tree Async Rust 可观测性的灵丹妙药 - 赵梓淇
Lifetime • 无栈协程 Async Rust 回顾 Rust 的无栈协程抽象 — Future Async Rust 回顾 • 通过 poll 驱动的状态机 • 组合嵌套为调度单元: Task • async fn 语法糖 Async Rust 观测与调试的痛点 Async Rust 回顾 • 特性: Future 灵活的可组合性 • 任意定制 Poll 的执行逻辑 (Join 无法追踪调用关系的变化 Async Rust 观测与调试的痛点 Async Rust 回顾 • 特性:用户态调度的无栈协程 • Pending Task 不存在栈空间 • 痛点:观测与调试工具无法还原 Pending Task 的执行状态 • 难以得知 Task 阻塞的位置和原因 • 难以调试 Async Stuck • ? 如何解决? Await-Tree Async Rust 可观测性的灵丹妙药 Tree 的设计原理与实现 • 追踪关键 Future 的生命周期和控制流 • Init, First Poll, Pending, Next Poll, Ready, Cancel • 实时将 Task 的执行状态维护为一棵树 • 显示目前正在阻塞 / 执行的 Await Point • 得名 Await-Tree 基本用例 Await Tree 的设计原理与实现 基本用例 Await0 码力 | 37 页 | 8.60 MB | 1 年前3C++高性能并行编程与优化 - 课件 - 06 TBB 开启的并行编程之旅
https://www.bilibili.com/video/BV1fa411r7zp 的 1:18:48 上一课的案例代码:基于标准库 基于 TBB 的版本:任务组 • 用一个任务组 tbb::task_group 启动多个 任务,一个负责下载,一个负责和用户交 互。并在主线程中等待该任务组里的任务 全部执行完毕。 • 区别在于,一个任务不一定对应一个线程 ,如果任务数量超过 CPU 最大的线程数, 让人咋 用? 第 4 章:任务域与嵌套 https://link.springer.com/chapter/10.1007%2F978-1-4842-4398-5_12 任务域: tbb::task_arena 任务域:指定使用 4 个线程 嵌套 for 循环 嵌套 for 循环:死锁问题 死锁问题的原因 • 因为 TBB 用了工作窃取法来分配任务: 当一个线程 t1 做完自己队列里全部的工 这种技术又称为线程池( thread pool ),避免了 线程需要保存上下文的开销。但是需要我们管理 一个任务队列,而且要是线程安全的队列。 struct Task { int x0, y0; int nx, ny; }; std::queue<Task> q; 1 2 3 4 解决 3 :每个线程一个任务队列,做完本职工作后可以认领其他线程的任务 工作窃取法( work-stealing0 码力 | 116 页 | 15.85 MB | 1 年前3No Silver Bullet – Essence and Accident in Software Engineering
“Therefore it appears that the time has come to address the essential parts of the software task, those concerned with fashioning abstract conceptual structures of great complexity. I suggest: validation can only establish that a program meets its specification, the hardest part of the software task is arriving at a complete and consistent specificationEnvironments and tools • How much more gain Environments and toolsA Modern Take on Accidental Complexity • Yak Shaving - the phenomenon where one task leads to another, which leads to another, until you end up working on something that seems completely0 码力 | 35 页 | 1.43 MB | 5 月前3使用硬件加速Tokio - 戴翔
misuse-resistant. This helps prevent common bugs, such as unbounded queues, buffer overflows, and task starvation. Reliable Building on top of Rust, Tokio provides a multi-threaded, work-stealing scheduler0 码力 | 17 页 | 1.66 MB | 1 年前3基于 Rust Arrow Flight 的物联网和时序数据传输及转换工具 霍琳贺
futures::future::Abortable 可用于短路一个 stream • tokio_util::sync::CancellationToken 可用于向一个或多个任务发出取 消信号, Task 内使用 tokio::select! 宏执行相关取消操作。 • tokio::signal::ctrl_c 接收 Ctrl-C 信号,可用于最终程序退出时的取 消操作。 • 谨慎处理任务中0 码力 | 29 页 | 2.26 MB | 1 年前3
共 8 条
- 1