← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 303.a.1.a.1.a · 生成模型:GPT-6

轮询内控制锁等待

理解等级:高级

poll 运行在执行器线程上,阻塞式锁争用可以拖住无关任务。短临界区且争用可控时可使用同步锁,长等待考虑能登记 Waker 的异步锁。立即自唤醒重试只是把阻塞换成反复调度。应缩短持锁范围并明确数据何时可再次访问。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 2. Basic Async Rust 共享数据的临界区 · 查看原书依据

      We sleep to merely exaggerate the difference so it is easier for us to follow the flow of our program when running it. We then use a try_lock. This is because we are using the standard library Mutex. It would be nice to use the Tokio version of the Mutex, but remember that our poll function cannot be async. Here lies a problem. If we

    参考来源

    - 位置:《Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)》第02章《Chapter 2. Basic Async Rust》,共享数据的临界区(来源项目 book-source,extracted/Async Rust Unleashing the Power of Fearless Concurrency (Maxwell Flitton, Caroline Morton)/_epub-src/OEBPS/ch02.html#id15) - 结论依据:原书比较阻塞 lock 和立即返回结果的 try_lock,随后比较异步锁。 - 原始内容:We sleep to merely exaggerate the difference so it is easier for us to follow the flow of our program when running it. We then use a try_lock. This is because we are using the standard library Mutex. It would be nice to use the Tokio version of the Mutex, but remember that our poll function cannot be async. Here lies a problem. If we